开发者

How to implement 2 tables in a single view (Not sectioned Table)

How can we create 2 table views in a single view without using section TableViews.., I just want to display two tableViews in the view screen.., Say.., I have dragged开发者_JS百科 two UITableViews from the Interface Builder to my view screen.., and i connected the IBOutlet defined in interface file.., AFAIK, we need to define two methods in the implementation file.. i.e.., numberOfRows and numberOfSections.., But I am confused.., doing that will change the tableView property of both the tables...

EDITED:

I want to create a horizontal scroll view..,with 3 tableViews of size 320 X 200.., What I did was dragged UIScrollView to the view in IB.., Then dragged 3 UITableViews into that scrollView.., What do I need to do next., to fill up the table contents ?


Table views are UIView. So you can add multiple table view as subview just like you can add multiple labels or buttons. However, if you want to use the same object as delegate for both table views then a little more work is needed. All the delegate methods are passed the table view for which the method has been called as the first parameter. You need to check that parameter to know for which table view the method is called. For example:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (tableView == self.tableView1) {
        return [arrayForView1 count];
    }

    if (tableView == self.tableView2) {
        return [arrayForView2 count];
    }

}


Just drag two table view inside your view, and set those dataSource and delegate to files owner.


As far as I understand you, you want to display different data in the two table views? If so, just create a viewcontroller with xib file, setup the two tableviews inside this xib file.

Then, you create two tableviewcontrollers (one for each tableview) without xib file.

Create instances of these tableviewcontrollers in the viewcontroller and set the delegate / data-source relations programatically.

Should work so far but I don't think users will like this^^

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜