I’m quite new to iphone development. I created To-Do List app using coredata. so, my table view dynamically updating.
I want to add table view row textlabels to a NSMutable array (that means row1 text label to 1st index position of MutableArray , row2 text label to 2nd index position of Array)
this is my table view cellfor indexpath method
- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *HeroTableViewCell = @"HeroTableViewCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:HeroTableViewCell];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:HeroTableViewCell] autorelease];
}
NSManagedObject *oneHero = [self.fetchedResultsController objectAtIndexPath:indexPath];
NSInteger tab = [tabBar.items indexOfObject:tabBar.selectedItem];
switch (tab) {
case kByName:
cell.textLabel.text = [oneHero valueForKey:@"name"];
cell.detailTextLabel.text = [oneHero valueForKey:@"secretIdentity"];
break;
case kBySecretIdentity:
cell.detailTextLabel.text = [oneHero valueForKey:@"name"];
cell.textLabel.text = [oneHero valueForKey:@"secretIdentity"];
default:
break;
}
//listData = [[[NSMutableArray alloc] init]autorelease];
//if(indexPath.row==1){
//[listData addObject: cell.textLabel.text];
return cell;
}
commented lines are how I’m try to do it. But I’m struggle to add those data as I want.
Please help me
Have the line
listData = [[[NSMutableArray alloc] init]];some where out of thecellForRowAtIndexPath:method, so that it won’t be reallocated every time a cell loads. And you can have the line[listData addObject: [oneHero valueForKey:@"secretIdentity"]];
where it is now currently.Edit: Better you can do this at some method, like viewDidLoad:, to make sure all elements are added to the array.