我想把一個UIButton
放在UITableViewCell
裏面。把一個UIButton放在UITableView裏面
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...
該引擎收錄鏈接中包含的代碼對整個cellForRowAtIndexPath()
功能(有問題的UITableView
)。
看看iOS UITableView文檔中的* Customizing Cells *部分:http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/ TableViewCells/TableViewCells.html – 2011-04-28 15:09:41