iOS 5情节提要:为每个UIView定制以编程方式创建的UITableView [英] iOS 5, storyboards: customize programmatically created UITableView for every UIView
问题描述
在情节提要中,我创建了一个UIViewController并将两个以上的UIViews添加到同一情节提要中.然后添加了UISegmentedControl以启用这些UIView之间的切换.
In storyboards I've created an UIViewController and added more two UIViews to the same storyboard. Then added UISegmentedControl to enable switch between these UIViews.
我用来在UIView之间切换的方法:
The method I use to switch between UIView:
-(IBAction)segmentValueChaged:(id)sender
{
if(self.segment.selectedSegmentIndex==0)
{
[self.coinageView removeFromSuperview];
[self.view addSubview:nominalsView];
[self populateNominals:self.subCountryID];
}
else
{
[self.nominalsView removeFromSuperview];
[self.view addSubview:coinageView];
}
}
以及在UIView上添加UITableView的方法:
And the method which adds a UITableView on an UIView:
-(void)populateNominals:(int)subCountryID
{
UITableView *nominalsTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 372) style:UITableViewStylePlain];
//nominalsTableView.dataSource = self;
//nominalsTableView.delegate = self;
[self.nominalsView addSubview:nominalsTableView];
}
这种方法很好用,切换段时弹出一个表格.
This approach works fine and I'me getting a table popped up when switching the segment.
我的问题是,在哪里可以为每个段(UIView)自定义每个tableView?问题是我需要两个外观完全不同的表(不同的设计,cellForRowAtIndexPath和在didSelectRowAtIndexPath时的导航不同).
My question is, where can I customize every tableView for every segment (UIView)? The problem is that I need two quite-different-looking tables (different design, cellForRowAtIndexPath and different navigation while didSelectRowAtIndexPath).
谢谢.
推荐答案
如果您有两个看上去完全不同的表",请设置dataSource并将每个tableview委托给一个不同的对象.含义是为每个表创建一个类/对象,该类/对象将用作数据源并代表一个表.通常,这些设置为自我",但没有什么可说的.
If you have "two quite-different-looking tables" then set the dataSource and delegate for each tableview to a different object. Meaning create a class/object for each table that will function as the dataSource and delegate for a table. Normally a these are set to 'self' but there is nothing to say they have to be that.
如果您懒惰并且不关心漂亮的可重用代码,则只需将if/else语句放在所有tableView委托和dataSource调用中,然后比较传入的tableView变量以查看它是什么表.但这有点丑陋,很容易搞砸.尤其是当它增长到2种以上不同类型的表时.
If your lazy and don't care about beautiful reusable code you could just put if/else statements in all the tableView delegate and dataSource calls and and compare the passed in tableView variable to see what table it is. But that is a bit ugly and easy to mess up. Especially if it grows to more than 2 different kinds of tables.
这篇关于iOS 5情节提要:为每个UIView定制以编程方式创建的UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!