2012-08-27 40 views

回答

0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 
    [self configureCell:cell atIndexPath:indexPath]; 


    for (int x = 0; x < [[self.fetchedResultsController sections] count]; x++) { 

     id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:x]; 

     int d = [sectionInfo numberOfObjects]; 

     if(indexPath.section == x){ 

      if (indexPath.row == 0 || indexPath.row == d-1) { 

       cell.backgroundColor = [UIColor blackColor]; 

      }else{ 

       cell.backgroundColor = [UIColor whiteColor]; 

      } 

     } 
    } 

    return cell; 
} 
2

在你UITableViewDataSource方法tableView:cellForRowAtIndexPath:做這樣的事情,你的細胞已經成立後:

if (indexPath.row == 0 ||  
    indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 1) { 
    cell.backgroundColor = [UIColor redColor]; // or anything you want. 
} 
+0

看看我的答案。您可以分別更改第一個或最後一個單元格或中間單元格的顏色。 – NamshanNet

+0

Yaser,如果你發佈了一個問題並想自己回答,請選中**回答自己的問題**選項,這樣問題纔會顯示出來,直到你發佈了你的答案。 http://blog.stackoverflow.com/2011/07/its-ok-to-ask-and-answer-your-own-questions/ – DrummerB

相關問題