tGi*_*ani 4 iphone uitableview ios
使用iOS 5 ::我有一个场景,我必须使用自定义单元格创建一个tableView.自定义单元格有一个名为TainingCellController的UITableViewCell子类和一个NIB文件TrainingCell.xib.而父表放在一个名为TrainingController的UIViewController中.
现在我真的很想知道,CustomCell与文件所有者的关系,谁接收IBActions或IBOutlets ..
在Custom Cell NIB文件中,我可以更改文件所有者(默认设置为NSObject),也可以单击单元格本身并将其类从UITableViewCell更改为TrainingCellContrller.
这两个选项的适当类应该是什么?应该在哪里定义IBActions和IBOutlets(TrainingCellController或TrainingController)?
什么如果我需要在TrainingCellController中定义按钮动作时在TrainingCellController中定义"自定义单元格中的标签"的插座?
你将把你UITableViewCell
的班级设置到你CustomCell
的班级,你将IBoutlet
在CustomCell
课堂上定义并连接它们.
然后你将你的Xib的文件所有者设置为你的ViewController
,并在你的ViewController
声明中声明一个
IBOutlet CustomCell *yourClassLevelCell;
Run Code Online (Sandbox Code Playgroud)
并将此连接IBOutlet
到您的XibUITableViewCell
现在,当您在ViewController's
方法中初始化单元格时,您将cellForRowAtIndexPath
手动添加目标,如下所示:
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
}
Run Code Online (Sandbox Code Playgroud)