繁体   English   中英

双格按钮动作

[英]double cell button action

我有一个UITableView,其中有一个针对UITableViewCell的xib文件。

在UITableViewCell上,我添加了2个单元格数据-因为我想实现两列样式。 因此无法修改。 该单元有点复杂,它还有更多的组件,我想处理按钮UIControlEventTouchUpInside事件的动作。 它将在任务竞赛后下载一些内容并需要将按钮文本从“下载”更改为“查看”,例如。

如果我不处理多线程,异步的东西,但是需要的话,它将解决。 因此,我需要将按钮和索引传递给action方法,或者为按钮设置属性(在Java中很容易),但找不到它。

一半的代码如下所示:

    [buttonAction addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];

并且需要这样的东西:

-(void)buttonPressed:(UIButton*)button index: (int) index
{

}

在另一个问题中,索引是通过buttonAction.tag = index传递的,但是如果我更改该属性,那么我认为它不会起作用

UIButton * buttonAction =(UIButton *)[cell viewWithTag:205]; 在发表声明

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

有什么建议如何处理这种情况?

您可以UIButton类,并具有所需所有信息的属性。 然后使用@selector(buttonPressed:)将操作添加到TouchUpInside的按钮中

-(void)buttonPressed:(YourCustomButton *)sender  // or id and then you check it's class and cast to your custom button class
{
    // work with sender.yourProperty
}

编辑

 [button setTitle:@"Download" forState:UIControlStateNormal];
 [button setTitle:@"View" forState:UIControlStateReserved];

然后根据您的标题进行工作: button.currentTitle

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM