使用Singleton設計模式,這意味着這兩個表將從相同的情況下得到的數據源
class sharedDataSource : NSObject,UITableViewDataSource{
static var sharedInstance = sharedDataSource();
override init(){
super.init()
}
//handle here data source
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{
}
}
var tableOne = UITableView();
var tableTwo = UITableView();
tableOne.dataSource = sharedDataSource.sharedInstance;
tableTwo.dataSource = sharedDataSource.sharedInstance;
第一個和第二個表視圖控制器有什麼區別?您可以只使用一個,並在cellForRowAtIndexPath方法中檢查您需要爲部分 – azimov
中的每個案例顯示哪些單元格,並根據需要創建儘可能多的表格視圖,然後按照通常方式執行操作,但使用自定義UITableViewCell並設置一個將自定義單元格的屬性設置爲「擁有」和「需要」,在tableview中要顯示「擁有」激活擁有的屬性,在tableview中顯示所需的激活所需屬性。根據需要從服務器中相互減去一個或重複,就是這樣吧 – Loxx
你真的想共享數據源嗎?您將在這些視圖控制器之間引入緊密耦合,這可能會在未來導致維護問題。您可能會共享一個模型,但您通常不會建議共享數據源。 – Rob