another objective c question for you. Probably a simple one too…
In my viewDidLoad method I am setting a variable. I need to access this within - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath however I am receivig the following error and I don’t really know a way to sort it!
-[CFString intValue]: message sent to deallocated instance 0x592dcb0
- (void)viewDidLoad
{
//code to get json is here
totalInCategory = [parsedJson objectForKey:@"TotalInCategory"];
NSLog(@"totalincat %i",[totalInCategory intValue]);
[super viewDidLoad];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)celllforRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"totalincat %i",[totalInCategory intValue]);
if((indexPath.row == [myArray count]-1)&&(indexPath.row < [totalInCategory intValue]))
{
//code to get more rows
[self.tableView reloadData];
}
}
I have NSString *totalInCategory; set up and synthesized.
totalInCategory is fine within viewDidLoad (as far as I’m aware that is), but nowhere else… any ideas would be really handy!
Retain the data…
objectForKey returns an autoreleased object which you need to retain if you wish to use it. Don’t forget to add a
[totalInCategory release];in the dealloc.