我有一个名为groupConversation
的全局数组,该数组填充在另一个UIViewController
中。首先,数组为空,但当用户单击另一个UIViewController
中的按钮时,它将被填充。但是,UITableViewController
出现在另一个UIViewController
之前。但是当在另一个UIViewController
中单击按钮同时填充数组时,它会将用户弹出UITableViewController
但UITableViewController
为空,我不明白为什么?如何让UITableViewController
包含数据?
import UIKit
class GroupChatTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.navigationBar.tintColor = UIColor.redColor()
self.navigationItem.backBarButtonItem?.tintColor = UIColor.redColor()
println()
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
override func viewWillAppear(animated: Bool) {
self.navigationController?.navigationBar.tintColor = UIColor.orangeColor()
self.navigationItem.backBarButtonItem?.tintColor = UIColor.orangeColor()
self.tableView.reloadData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return groupConversation.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let groupChatCell = tableView.dequeueReusableCellWithIdentifier("groupChatCell", forIndexPath: indexPath) as UITableViewCell
groupChatCell.textLabel?.text=groupConversation[indexPath.row]
return groupChatCell
}
}