UItableView:无法更改单元格的颜色(UItableView: unable to change color of a cell)

编程入门 行业动态 更新时间:2024-10-28 20:17:09
UItableView:无法更改单元格的颜色(UItableView: unable to change color of a cell)

我是iPhone编程的新手,我无法更改表格视图单元格的背景

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; if((indexPath.row%2)!=0) { [cell setBackgroundColor:[UIColor clearColor]]; [cell setBackgroundColor:[UIColor redColor]]; //[cell ]; } else { [cell setBackgroundColor:[UIColor whiteColor]]; } } // Configure the cell... [cell setText:[menuItems objectAtIndex:indexPath.row]]; return cell;

}

请帮我理解为什么??

提前完成

I am new to iPhone programming and I was unable to change background of my Table view cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; if((indexPath.row%2)!=0) { [cell setBackgroundColor:[UIColor clearColor]]; [cell setBackgroundColor:[UIColor redColor]]; //[cell ]; } else { [cell setBackgroundColor:[UIColor whiteColor]]; } } // Configure the cell... [cell setText:[menuItems objectAtIndex:indexPath.row]]; return cell;

}

Please help me to understand the reason why??

Thanx in advance

最满意答案

好的,得到了​​答案

- (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath { cell.backgroundColor = indexPath.row % 2 ? [UIColor colorWithRed: 0.0 green: 0.0 blue: 1.0 alpha: 1.0] : [UIColor whiteColor]; cell.textLabel.backgroundColor = [UIColor clearColor]; cell.detailTextLabel.backgroundColor = [UIColor clearColor]; }

Ok got the answer

- (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath { cell.backgroundColor = indexPath.row % 2 ? [UIColor colorWithRed: 0.0 green: 0.0 blue: 1.0 alpha: 1.0] : [UIColor whiteColor]; cell.textLabel.backgroundColor = [UIColor clearColor]; cell.detailTextLabel.backgroundColor = [UIColor clearColor]; }

更多推荐

本文发布于:2023-07-26 06:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1272226.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元格   颜色   UItableView   unable   cell

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!