objectAtIndex:indexPath.row method always causes exception in IOS

Posted by kalkin on Stack Overflow See other posts from Stack Overflow or by kalkin
Published on 2012-11-14T04:45:44Z Indexed on 2012/11/14 5:00 UTC
Read the original article Hit count: 121

Filed under:
|
|
|

Hi I always seem to get exception when I use objectAtInded method to retrieve NSString from an array. I am reading data from a dictionary which is in the "PropertyList.plist" file.My code is

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *path = [[NSBundle mainBundle] pathForResource:@"PropertyList"
                                                     ofType:@"plist"];
    names = [[NSDictionary alloc]
             initWithContentsOfFile:path];

    keys = [[[names allKeys] sortedArrayUsingSelector:
             @selector(compare:)] retain];
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger section = [indexPath section];
    NSUInteger row = [indexPath row];

    NSString *key  = [keys objectAtIndex:section];
    NSArray *nameSection = [names objectForKey:key];
    static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier];
    if(cell == nil)
    {
        cell = [[[UITableViewCell alloc]
                 initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SectionsTableIdentifier] autorelease];
    }
    cell.textLabel.text = [nameSection objectAtIndex:row];
    return cell;
}

The exception happens on the method "cellForRowAtIndexPath" in the line

cell.textLabel.text = [nameSection objectAtIndex:row];

The error message is

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x6832440

Where ever I use "[nameSection objectAtIndex:row];" type of statement it always get exception.

© Stack Overflow or respective owner

Related posts about ios

Related posts about xcode