我想实现tablecell,其中有一个text = 0的标签和两个带有'+'和' - '的按钮
知道如何更改uitablecell的标签。
提前致谢。
答案 0 :(得分:1)
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier{
UIButton * mp;
UILabel *l1;
UITableViewCell *cell=[[[UITableViewCell alloc]initWithFrame: CGRectMake(0, 0, 300, 60) reuseIdentifier:nil] autorelease];
l1=[[UILabel alloc] initWithFrame:CGRectMake(100.0, 15.0, 400.0, 40.0)];
l1.tag=1;
l1.font=[UIFont fontWithName:@"AppleGothic" size:17];
l1.textColor=[UIColor blackColor];
l1.backgroundColor=[UIColor clearColor];
l1.numberOfLines=3;
[cell.contentView addSubview:l1];
[l1 release];
mp=[[UIButton alloc] initWithFrame:CGRectMake(250, 25, 50, 20)];
mp.tag=2;
mp.font=[UIFont boldSystemFontOfSize:14];
mp.textColor=[UIColor blueColor ];
[mp addTarget:self action:@selector(mapbtnpressed:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:mp];
[mp release]
return cell;
}
在cellForRowAtIndexPath方法中调用
cell=[self getCellContentView:CellIdentifier];
labelname=(UILabel *)[cell viewWithTag:1];
[cell.contentView addSubview:labelname];
click event
+
labelname.text=[NSString stringWithFormat:@"%d",[lanename.text intvalue]+1];
-event
labelname.text=[NSString stringWithFormat:@"%d",[lanename.text intvalue]-1];
答案 1 :(得分:0)
尝试使用setText:
UILabel
方法
[urLabel setText:newText];
- (IBAction)plusButtonPressed
{
int value = [urLabel.text intValue];
value++;
[urLabel setText:[NSString stringWithFormat:@"%d",value]];
}
答案 2 :(得分:0)
查看this page文档。特别是,清单5-3 。基本思路是所有自定义子视图都应添加到表格单元格的contentView
。