我正在使用以下viewController
设置
我要做的是从array
访问placesTabBar
个地点,并在两个navigationControllers
中显示这些地点。其中一个控制器将包含一个位置列表,而另一个控制器将仅用于您正在参加的位置。在选择一个单元格时,它会在切换时更新另一个视图控制器,表示你要去那个地方。我使用以下代码:
AllPlaces ViewController
class AllPlaces: UITableViewController {
var delegate:placesTabBar!
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return delegate.placeDataArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
cell.textLabel?.text = delegate.placeDataArray[indexPath.row].description
return cell
}
}
AttendingPlaces ViewController class AttendingPlaces:UITableViewController {
var delegate:placesTabBar!
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return delegate.placeDataArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
cell.textLabel?.text = delegate.placeDataArray[indexPath.row].description
return cell
}
}
TabBarController
class placeData: Equatable {
var description : String
var selected : Bool
init (description : String, selected : Bool) {
self.description = description
self.selected = selected
}
}
class placesTabBar: UITabBarController, CustomTabBarDelegate {
var placeDataArray = Array<placeData>()
override func viewDidLoad() {
placeDataArray = [placeData(description: "Afghanistan", selected: false), placeData(description: "Albania", selected: false)]
var table1 = AttendingPlaces()
var table2 = AllPlaces()
table1.delegate = self
table2.delegate = self
var navController1 = UINavigationController(rootViewController: table1)
var navController2 = UINavigationController(rootViewController: table2)
self.viewControllers = [navController1, navController2]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
现在我只是尝试使用数组中的两个位置加载表。但是,我得到一个“无法使用标识符Cell出列的单元格”错误。在tableViewControllers
中都正确设置了重用标识符,因此我不确定发生了什么。这可能是我尝试在两个viewControllers
之间共享数据的方式吗?