如何将 UIButton 放入 uitableview 单元格中?
我可以使用 textlabel
和 detaillabeltext
创建一个 tableview
。
除此之外,是否可以将 UIButton
添加到单元格中。
我的意思是在详细标签文本之后,我可以放置一个 UIButton
(如“删除”按钮)
目前我有以下代码
// 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;
}
感谢您的时间和帮助!
I am able to create a tableview
with textlabel
and with detaillabeltext
.
In addition to that, is it possible to add UIButton
into the cell.
I mean after the detaillabeltext, can i place a UIButton
( like "Remove" button )
Currently i have the following code
// 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;
}
Thanks for you time and helps!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将按钮或任何其他控件添加到单元格的内容视图中。
将任何控件添加到单元格的内容视图
You can add button or any other control to the content view of cell.
Add any control to cell's content view