Search code examples
xcodejsonuitableviewnsmutablearrayios6.1

UItableview crash at cellForRowAtIndexPath because of my NSMutableArray containing special characters


I am fetching data from web service and store on the NSMutableArray

app.firstName=[[NSMutableArray alloc]initWithObjects:[[[luckyNumbers    valueForKey:@"findProviders"]valueForKey:@"quotes"]valueForKey:@"firstName"], nil];
NSLog(@"app.first %@",app.firstName);

app.first 
(
    (
    "Tom ",
    shamu,
    Shiva
    )
)
cell.Phone.text=[app.firstName objectAtIndex:indexPath.row];

Console terminating the app due to the below uncaught exception:

'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'


Solution

  • In app.firstName at index 0 you now have an array.and you assign it display in a string .Hence the crash

    [app.firstName objectAtIndex:indexPath.row]; returns an array not a string.

    Try

    NSArray *tempArray=[app.firstName objectAtIndex:0];
    cell.Phone.text=[tempArray objectAtIndex:indexPath.row];
    

    I think you need to edit datasource methods for this change