iPhone-将按钮添加到UITableView中的选定行 [英] iPhone - Adding button to selected row in UITableView

查看:45
本文介绍了iPhone-将按钮添加到UITableView中的选定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XCode的基于导航的应用程序模板来创建以UITableView为中心的应用程序.

I am using XCode's Navigation-based Application template to create an app that centers around an UITableView.

当用户在UITableView中选择一行时,我想在该所选单元格内显示一个按钮.我只想在所选单元格中显示此按钮,而不要在其他任何单元格中显示.如果用户此后选择其他单元格,也会发生同样的情况.

When the user selects a row in the UITableView I want to display a button inside of that selected cell. I want to display this button only in the cell selected and not in any other cells. The same goes if the user selects a different cell afterwards.

我该怎么做?有可能吗?

How do I go about doing this? Is it possible?

推荐答案

子类UITableViewCell并向其中添加按钮.

Subclass UITableViewCell and add the button to it.

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        button = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
        [button setFrame:CGRectMake(320.0 - 90.0, 6.0, 80.0, 30.0)]; 
        [button setTitle:@"Done" forState:UIControlStateNormal];
        button.hidden = YES;
        [self.contentView addSubview:button];
    }
    return self;
}

然后覆盖setSelected,如下所示:

Then override setSelected like so:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    self.button.hidden = !selected;
}

这篇关于iPhone-将按钮添加到UITableView中的选定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆