Ios 如何更改组UITableView中第一行和最后一行的颜色?
如何更改组UITableView中第一行和最后一行的颜色 我想和你们分享我的解决方案,但我不知道如何,所以我提出了这个问题。很抱歉。Ios 如何更改组UITableView中第一行和最后一行的颜色?,ios,xcode,ios5,xcode4.2,ios6,Ios,Xcode,Ios5,Xcode4.2,Ios6,如何更改组UITableView中第一行和最后一行的颜色 我想和你们分享我的解决方案,但我不知道如何,所以我提出了这个问题。很抱歉。-(UITableViewCell*)tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPa
-(UITableViewCell*)tableView:(UITableView*)tableView cellforrowatinexpath:(nsindepath*)indepath
- (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;
}
{
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:@“cell”];
[self-configureCell:cell-atIndexPath:indexPath];
对于(int x=0;x<[[self.fetchedResultsController节]计数];x++){
id 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];
}否则{
cell.backgroundColor=[UIColor whiteColor];
}
}
}
返回单元;
}
在您的UITableViewDataSource
方法表格视图:cellForRowAtIndexPath:
在设置单元格后,执行以下操作:
if (indexPath.row == 0 ||
indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 1) {
cell.backgroundColor = [UIColor redColor]; // or anything you want.
}
看看我的答案。您可以分别更改第一个或最后一个单元格或中间单元格的颜色。Yaser,如果您发布了一个问题并想自己回答,请选中“回答您自己的问题”选项,这样,在您发布答案之前,问题不会显示。