sub*_*e-c 2 iphone cocoa-touch objective-c
我真的非常绝望地尝试将UIImageView添加到UITableViewCell.backgroundView.我所有的努力都导致了这种糟糕的渲染:
替代文字http://img.skitch.com/20091123-ch8wk6pdxqkrn9tpftnhusigcy.jpg
看起来细胞的标签的白色背景位于细胞背景的顶部并覆盖其部分.
我尝试将标签的背景颜色设置为clear或其他颜色,并且没有任何事件.它总是白色的.
我之所以知道它是文本标签背景导致这个白色区域的原因是,如果我不这样做[cell setText:@"Cell text here"]; 白色区域消失了,我只看到了细胞的背景图像.
这是我正在使用的代码.表视图添加到.xib文件中,UITableView添加到UIViewController:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [myCollection.items count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger rowIndex = indexPath.row;
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"darkCellBackground.png"]];
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"darkCellBackground.png"]];
}
[cell setText:@"Cell text here"];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
// [self.navigationController pushViewController:anotherViewController];
// [anotherViewController release];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
Run Code Online (Sandbox Code Playgroud)
我确定我做错了什么但不能弄清楚是什么.
解决方案在这里:更改UITableViewCell textLabel背景颜色以清除
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[[cell textLabel] setBackgroundColor:[UIColor clearColor]];
[[cell detailTextLabel] setBackgroundColor:[UIColor clearColor]];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10120 次 |
| 最近记录: |