You might reload the table view before initialising array , or may be your array is empty when you use it !
Like when you use :
NSString *xyz = [self.your_array objectAtIndex:indexPath.row];
in cellForRowAtIndexPath , Try fllowing code that wont crash your app !
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"xyz_cell";
long nodeCount = [self.your_array count];
if (nodeCount == 0 && indexPath.row == 0)
{
Home_CellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[Home_CellTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] ;
cell.lbl.textAlignment = NSTextAlignmentCenter;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.lbl.text = @"No Posts yet !";
return cell;
}
else{
Home_CellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[Home_CellTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
} // Your Code Goes HERE .... NSString *xyz = [self.your_array objectAtIndex:indexPath.row]; }
so , for empty array it wont find value for key one and your app wont crash !
I hope it helps ,