• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
MutableArray and TableView Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

MutableArray and TableView Question


  • Subject: MutableArray and TableView Question
  • From: Chris Share <email@hidden>
  • Date: Mon, 18 Oct 2010 23:02:48 -0700 (PDT)

I'm developing an app in which the user is able to navigate to a folder and
select files. A list of the selected files for each folder is displayed in a
table. This process is repeated by the user. Each time the user navigates to a
new folder and selects a new group of files the process starts from the
beginning (i.e. the list of files shown in the table does not increase
cumulatively, it resets each time, only showing the files in the current
folder).

I'm using an NSMutable array as my data source for the table. The problem I'm
having is in clearing the array for each new folder.

Here's the coder that I'm using:

-(IBAction)openButtonClick:(id)sender {
NSLog(@"Open button clicked!");
int i;

// Clear the input array.
[inputArray removeAllObjects];


// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanelopenPanel];


// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];


// Disable the selection of directories in the dialog.
[openDlg setCanChooseDirectories:NO];


// Enable the selection of files in the dialog.
[openDlg setAllowsMultipleSelection:YES];


// Display the dialog.  If the OK button was pressed,
// process the files.
if([openDlg runModalForDirectory:nilfile:nil] == NSOKButton) {


// Get an array containing the full filenames of all
// files and directories selected.
NSArray* files = [openDlg filenames];
// Loop through all the files and process them.
for(i = 0; i < [files count]; i++) {
NSString* fileName = [files objectAtIndex:i];
[inputArray addObject:fileName];
}

[inputTablereloadData];
}
}

When I run this code I get the following error:

*** -[NSCFArray objectAtIndex:]: index (0) beyond bounds (0)

I assume that it's the [inputArray removeAllObjects] that's causing the problem
(?) If I remove this line, the code works but the filenames keep getting added
to the array which isn't what I want.

How do I fix this?

Cheers,

Chris



_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: MutableArray and TableView Question
      • From: Graham Cox <email@hidden>
    • Re: MutableArray and TableView Question
      • From: Quincey Morris <email@hidden>
    • Re: MutableArray and TableView Question
      • From: Conrad Shultz <email@hidden>
  • Prev by Date: Re: How to create secondary Thread that listens to event taps?
  • Next by Date: Re: MutableArray and TableView Question
  • Previous by thread: Invitation to connect on LinkedIn
  • Next by thread: Re: MutableArray and TableView Question
  • Index(es):
    • Date
    • Thread