开发者

How to check whether the UITableViewCells are blank

I am using indexpathforvisiblerows which gives the indexpaths of the visible rows in uitableview. How can i check for the blank cells in the returned indexpaths?.

` NSArray *visiblePaths = [self.rootViewController.accountTableView indexPathsForVisibleRows];

for (NSIndexPath *indexPath in visiblePaths) {

    UITableViewCell *cell = [self.rootViewController开发者_StackOverflow.accountTableView cellForRowAtIndexPath:indexPath];
   // I am getting the issue when i call this function 
        cell.detailTextLabel.text = [self getLastCallDate:indexPath];


}

// getLastCallDate function

Account *account = [self.fetchedResultsController objectAtIndexPath:indexPath]; NSString *lastCallDate;

if ([[account Calls] count] > 0) {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY-MM-dd"];

    Call *call = [[account Calls] objectAtIndex:0];

     lastCallDate = [NSString stringWithFormat:@"Last Call Date: %@",[dateFormatter stringFromDate:call.date]];

    //NSLog(@"detail - %@", cell.detailTextLabel.text);
    [dateFormatter release];
    return lastCallDate;
}
else
    lastCallDate =@"";
return lastCallDate;

` While searching fetched results controller will not have the values as many as the visible rows which leads to array bound execption


Before calling getLastCallDate:, check whether indexPath.row is less than the number of items in your data source. Something like-

for (NSIndexPath *indexPath in visiblePaths) 
{
     if(indexPath.row < [self.items count]) //items is your data source array
     {
          //your code
     }
}


I'm assuming that you have a plain UITableView without section header, just rows. Then the number of rows shown on the display tableView.frame.size.height / tableView.rowHeight. Subtract the number of visible rows.

How to check whether the UITableViewCells are blank

With the above algorithm I get total rows 16 visible cells 5.

Now it's up to you to calculate 16 - 5.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜