如何解决如何将UIButton放入uitableview单元格?
| 我可以用textlabel
和detaillabeltext
创建tableview
。
除此之外,还可以在单元格中添加UIButton
。
我的意思是在detaillabel文本之后,可以放置一个UIButton
(例如\“ Remove \”按钮)
目前我有以下代码
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//-----------------------------------------------------------------------------------------------------
{
static Nsstring *CellIdentifier = @\"Cell\";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
profileName = [appDelegate.sentItemsList objectAtIndex:indexPath.row];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
Nsstring *subjectData = [profileName.sent_subject stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
cell.textLabel.text = [Nsstring stringWithFormat: @\"%@ \",subjectData];
cell.textLabel.font = [UIFont boldSystemFontOfSize:13];
Nsstring *CompanyName = [profileName.sent_content stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
cell.detailTextLabel.text = [Nsstring stringWithFormat: @\"%@ \",CompanyName];
cell.detailTextLabel.font = [UIFont systemFontOfSize:10];
cell.accessoryType = UITableViewCellAccessoryDetaildisclosureButton;
cell.backgroundColor = [UIColor colorWithRed:230.0/255.0 green:249.0/255.0 blue:230.0/255.0 alpha:2.0];
return cell;
}
感谢您的时间和帮助!
解决方法
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@\"Show View\" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0,210.0,160.0,40.0);
[cell addSubview:button];
,您可以将按钮或任何其他控件添加到单元格的内容视图。
UIButton *cellButton = [[UIButton alloc]init];
[cellButton addTarget:self action:@selector(uploadData:)forControlEvents:UIControlEventTouchDown];
[cellButton setTitle:@\"Upload Now\" forState:UIControlStateNormal];
cellButton.frame = CGRectMake(100,180,150,35);
[cell.contentview addSubview:cellButton];
[cellButton release];
将任何控件添加到单元格的内容视图
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。