I want to know if it's allowed to use Multiple UItableView
in the same View (i don't see any thing in the Apple's Human Interface Guidelines) and if it's OK, How to load different DataSource
in viewDidLoad
for each UITableView
?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
You can have multiple table views in a single view. Add tags to each table view and with use of tableview.tag you can load data into tableviews separately.
Example:
Yes you can. The issue is that each
UITableView
will use the sameUITableViewDataSource
andUITableViewDelegate
. Therefore you must determine which table view you are working with in each of the necessary delegate methods.For example:
You can most certainly have multiple table views. You would want to make sure you keep a pointer around to each one, then in your data source methods, you would do something like this:
This would be the same for all delegate / data source methods, which is why they give you which table view as a parameter.
You can set tag for each table. Then apply on that condition in tableview delegate method, for example:
To make life easier, you can pass in two different delegate to the UITableView. If you pass in the same delegate, you will have to do a lot of if statements. By creating two different delegate it will allow your code to be a lot cleaner.
IMO the cleanest solution would be to have one controller for each tableview.
If you use one controller for n tableview, you will have to use if-statemenst in many places, in
– numberOfSectionsInTableView:
– tableView:numberOfRowsInSection:
– tableView:titleForHeaderInSection:
Basically in all UITableViewDatasource-Protocol methods that you will need to implement.
So if you need to change something, you have to change it in many places.
If you use one controller class for one tableview, you won't have to check at all.
UITableViewDatasource
protocol– numberOfSectionsInTableView:
,– tableView:numberOfRowsInSection:
,– tableView:cellForRowAtIndexPath:
-setDataSource:
for every tableview to an object of the right controller classI wrote an example code: https://github.com/vikingosegundo/my-programming-examples/tree/master/TwoTableViews
TwoTableViewsViewController.m