UITableviewCell中的一个按钮 [英] a button in UITableviewCell

查看:50
本文介绍了UITableviewCell中的一个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个nib文件创建了UItableViewCell,并在我的单元格中放置了一个按钮.我创建了一个IBAction来在用户单击按钮时关联一个动作.但是我崩溃了,我不知道这是什么问题,我已经设置了所有必要的东西.

I have UItableViewCell created with a nib file, and have put in my cell a button. i hace created an IBAction to associate an action when the the user click the button.but i have a crash and i don't know what it is the problem, i have set all the things necessary.

//in my .h
-(IBAction)go; 

//in my .m
-(IBAction)go 
{ 
    NSLog(@"hello");
} 

但是我崩溃了,在consol调试中什么也没显示.

but i have a crash and nothing is show in the consol debug.

我该如何在UITableviewcell中设置一个按钮,并与此按钮关联一个动作.谢谢你的回答

how can i set a button in UITableviewcell and associate with this button an action. thanks for your answer

推荐答案

以编程方式创建一个按钮,并将其添加到单元格的子视图中.将tag设置为indexPath.row值,然后将target添加到按钮.现在在目标中,您可以简单地使用:

Create a button programmatically and add it to the sub view of the cell. Set tag as the indexPath.row value and add target to the button. Now in the target you could simply use :

 -(void)buttonInsideCellIsPressed : (id)sender{
   UIButton *button = (UIButton *)sender; 
   NSIndexPath *indexPath = [NSIndexPath indexPathForRow:button.tag inSection:0];
   CustomCell *cell = (CustomCell*)[myTable cellForRowAtIndexPath:indexPath];

   // Here you may change the background image for the button for rollover or anything 
    }

这篇关于UITableviewCell中的一个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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