iPhone – 无法更改UITableViewCell背景色
发布时间:2020-12-14 19:36:11 所属栏目:百科 来源:网络整理
导读:我有UITableViewCell适合UITableView,但不知何故我进入编辑样式模式时无法改变背景颜色..我已经尝试了网上的所有内容,整天搜索,但仍然无法修复它(我’已经搜索过StackOverflow).请帮我. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRow
我有UITableViewCell适合UITableView,但不知何故我进入编辑样式模式时无法改变背景颜色..我已经尝试了网上的所有内容,整天搜索,但仍然无法修复它(我’已经搜索过StackOverflow).请帮我.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; MainTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray* views = [[NSBundle mainBundle] loadNibNamed:@"MainTableViewCell" owner:nil options:nil]; for (UIView *view in views) { if([view isKindOfClass:[UITableViewCell class]]) { cell = (MainTableViewCell *)view; } } } 解决方法
尝试自定义tableView:willDisplayCell:方法中的单元格,如下所示:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundColor = [UIColor redColor]; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |