Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在uisplitviewcontroller的detailview中更新表_Ios_Swift_Uitableview_Uisplitviewcontroller - Fatal编程技术网

Ios 在uisplitviewcontroller的detailview中更新表

Ios 在uisplitviewcontroller的detailview中更新表,ios,swift,uitableview,uisplitviewcontroller,Ios,Swift,Uitableview,Uisplitviewcontroller,所以我有一个UISplitViewController,在DetailView中我有一个UITableView 我要做的是从根视图控制器中获取所选单元格,并将其附加到在详细视图控制器中填充我的tableview的字符串中。我可以附加选择非常容易,但我需要的是更新部分的帮助 当您单击单元格时,它会将单元格中的值附加到全局变量main.BoatManifest,然后更新表。我只是不知道怎么做 下面是一些代码: import UIKit class DetailViewController: UIV

所以我有一个UISplitViewController,在DetailView中我有一个UITableView

我要做的是从根视图控制器中获取所选单元格,并将其附加到在详细视图控制器中填充我的tableview的字符串中。我可以附加选择非常容易,但我需要的是更新部分的帮助

当您单击单元格时,它会将单元格中的值附加到全局变量main.BoatManifest,然后更新表。我只是不知道怎么做

下面是一些代码:

import UIKit

class DetailViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, FullListCellDelegate {

@IBOutlet weak var tableView: UITableView!

func updateName(sender: FullListCell, detVC: DetailViewController) {
    tableView.reloadData()
}

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}


override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return main.BoatManifest.count
}


func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
 let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)

 // Configure the cell...
    cell.textLabel?.text = main.BoatManifest[indexPath.row]


 return cell
 }


}

struct Main {

var BoatManifest: [String] = []

}

var main = Main(BoatManifest: [" "])
这是我的详细视图的代码,底部的struct Main只是一个全局变量。我的主视图代码如下:

import UIKit

protocol NameSelectionDelegate: class {
func nameSelected()
}

class MasterViewController: UITableViewController {


var Names: [String] = ["John", "Mark", "Paul", "Jeremy"]

override func viewDidLoad() {
    super.viewDidLoad()

    if let split = self.splitViewController {
        let controllers = split.viewControllers
        self.detailViewController = (controllers[controllers.count-1] as! UINavigationController).topViewController as? DetailViewController
    }

    }

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
    // #warning Incomplete implementation, return the number of sections
    return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    // #warning Incomplete implementation, return the number of rows
    return Names.count
}


override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)

    cell.textLabel?.text = Names[indexPath.row]

    return cell
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    main.BoatManifest.append(Names[indexPath.row])
    NotificationCenter.default.addObserver(self, selector: #selector(loadList), name: NSNotification.Name(rawValue: "load"), object: nil)


}
func loadList(){
    //load data here
    self.tableView.reloadData()
}

}
我试图使用UISplitViewController教程来解决这个问题,但在细节视图控制器中没有tableview。当我选择单元格到DetailTableView并用附加文本更新它时,我需要发送一条消息


谢谢您的帮助。

若要查看我是否理解,您已经了解了当您单击单元格时,字符串被添加到相应的数据模型(
BoatManifest
?)中,现在您需要知道当模型更改时如何更新表?正确。不过,我想我找到了解决我原来问题的替代方案。我只需要在一个视图控制器中使用两个TableView,我找到了这个,它可以按照我想要的方式工作。