Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何更改组UITableView中第一行和最后一行的颜色?_Ios_Xcode_Ios5_Xcode4.2_Ios6 - Fatal编程技术网

Ios 如何更改组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

如何更改组UITableView中第一行和最后一行的颜色

我想和你们分享我的解决方案,但我不知道如何,所以我提出了这个问题。很抱歉。

-(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,如果您发布了一个问题并想自己回答,请选中“回答您自己的问题”选项,这样,在您发布答案之前,问题不会显示。