【发布时间】:2011-04-28 15:01:33
【问题描述】:
我正在尝试将UIButton 放入UITableViewCell。
UITableView 也有包含UILabels 的单元格,并且单元格有渐变背景被绘制到其中。我看到的问题是我的UIButton 只是一个没有文本显示的填充黑色单元格,并且更改颜色和背景颜色属性似乎没有任何作用。
这是我用来创建按钮的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"InAppViewController, doing this - width= %f", self.wdth);
static NSString *ProductTableIdentifier = @"ProductTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ProductTableIdentifier];
if (cell == nil)
{
if (self.wdth >= 700) {
CGRect cellFrame = CGRectMake(0, 0, (self.wdth - 100), 40);
cell = [[[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier: ProductTableIdentifier] autorelease];
// Set up some labels...
CGRect seenValueRect = CGRectMake(self.wdth-320, 0, 100, 40);
UIButton *seenValue = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[seenValue setBackgroundColor:[UIColor greenColor]];
seenValue.tag = kSeenValueTag;
seenValue.frame = seenValueRect;
[seenValue setTitle:@"I'm a clone" forState:UIControlStateNormal];
[cell.contentView addSubview:seenValue];
[seenValue release];
// Continue setting up cell...
pastebin 链接包含整个 cellForRowAtIndexPath() 函数的代码(用于相关的 UITableView)。
【问题讨论】:
-
查看 iOS
UITableView文档中的 Customizing Cells 部分:developer.apple.com/library/ios/#documentation/userexperience/…
标签: objective-c cocoa-touch ios uitableview uibutton