如何将 UIButton 放入 uitableview 单元格中?

发布于 2024-11-09 15:26:48 字数 1741 浏览 0 评论 0原文

我可以使用 textlabeldetaillabeltext 创建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

转角预定愛 2024-11-16 15:26:48
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 *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];
蹲在坟头点根烟 2024-11-16 15:26:48

您可以将按钮或任何其他控件添加到单元格的内容视图中。

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];

将任何控件添加到单元格的内容视图

You can add button or any other control to the content view of cell.

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];

Add any control to cell's content view

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文