在Custom UITableViewCell中的按钮上进行IBAction [英] IBAction on a button in Custom UITableViewCell

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

问题描述

使用iOS 5 ::我有一个场景,我必须使用自定义单元格创建一个tableView。
自定义单元格有一个名为TainingCellController的UITableViewCell子类和一个NIB文件TrainingCell.xib。虽然父表放在一个名为TrainingController的UIViewController中..

Using iOS 5 : : : I have a scenario where I must create a tableView with Custom Cells. The custom cells have a Controller called TainingCellController Subclass of UITableViewCell and a NIB file TrainingCell.xib . While the parent table is placed inside a UIViewController called TrainingController..

现在我真的很想知道,CustomCell与文件所有者的关系,他们收到了IBActions或IBOutlets ..

Now I am seriously wondering, the relationship of that CustomCell to the File Owner, who receives the IBActions or IBOutlets..

在Custom Cell NIB文件中,我可以更改文件所有者(默认设置为NSObject),也可以单击单元格本身并更改它的类UITableViewCell到TrainingCellContrller ..

In the Custom Cell NIB file, I can change the file owner (by default set to NSObject) and also can click on the cell itself and change it's class from UITableViewCell to TrainingCellContrller ..

这两个选项的适当类应该是什么?
IBActions& IBOutlets被定义(TrainingCellController或TrainingController)?

What should be the appropriate classes for these two options ?? Where should the IBActions & IBOutlets be defined (TrainingCellController or TrainingController)?

如果我需要在TrainingCellController中定义自定义单元格中的标签的插座,同时在TrainingController中定义按钮动作??

And what If I need outlets to "labels in custom cell" to be defined in TrainingCellController while button action to be defined in TrainingController??

推荐答案

您将 UITableViewCell 的类设置为您的 CustomCell 的类,您将在 CustomCell IBoutlet >类并连接它们。

You will set your UITableViewCell's class to your CustomCell's class and you will defined IBoutlets in CustomCell class and connect them.

然后你将Xib的文件所有者设置为 ViewController ,并在你的 ViewController 您将声明

And then you will set your Xib's file owner to your ViewController, and in your ViewController you will declare an

IBOutlet CustomCell *yourClassLevelCell;

并将此 IBOutlet 连接到您的Xib UITableViewCell

and connect this IBOutlet to your Xib's UITableViewCell

现在,当您在 ViewController的方法 cellForRowAtIndexPath 您将手动添加目标,如下所示:

now when you will initilize the cell inside your ViewController's method cellForRowAtIndexPath you will add target manually, something like this:

CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
   [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
   cell = yourClassLevelCell;
   [cell.button addTarget:self ... ];  
   //button is IBOutlet in your CustomCell class which you will have
   //connected to your Button in xib
}

这篇关于在Custom UITableViewCell中的按钮上进行IBAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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