Я пытаюсь отправить несколько строк из UITableView в другой UITableView с помощью функции prepareForSegue.Невозможно подстроить значение типа [String] с индексом типа [NSIndexPath] - prepareForSegue
Когда я просто отправляю один вариант во второй UITableView, приложение работает отлично, НО когда я выбираю несколько строк и отправляю их во второй UITableView в качестве заголовка (например, если я нажму сначала «a», строка, затем строка «d», а затем строка «c» ... второй UITableView просто показывает мне строку «c» в качестве заголовка, а не две другие строки), это дает ошибку.
Pic ошибки:
Эти строки я написал первый UITableView:
let array = ["a", "b", "c", "d", "e"]
@IBOutlet var initialTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
initialTableView.allowsMultipleSelection = true
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "segueA" {
if let destination = segue.destinationViewController as? Content {
if let selectedRows = initialTableView.indexPathsForSelectedRows {
destination.title = array[selectedRows]
}
}
}
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.array.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cellA", forIndexPath: indexPath) as UITableViewCell
cell.textLabel!.text = array[indexPath.row]
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
let cell = tableView.cellForRowAtIndexPath(indexPath)
if (cell?.accessoryType == UITableViewCellAccessoryType.Checkmark) {
cell!.accessoryType = UITableViewCellAccessoryType.None
} else {
cell!.accessoryType = UITableViewCellAccessoryType.Checkmark
}
}
Вторая точка зрения содержит следующие строки:
var contentArray:[String] = []
@IBOutlet var contentTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
contentArray.append(title!)
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return contentArray.count
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellContent = tableView.dequeueReusableCellWithIdentifier("cellContent", forIndexPath: indexPath) as UITableViewCell
cellContent.textLabel!.text = "Second test"
return cellContent
}
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return contentArray[section]
}
Итак, если я хочу выбрать кратные строки и отправить их из первых t во второй UITableView ... как я могу решить эту ошибку?
Спасибо.
Что вы хотите 'destination.title' быть установлен, если они выбирают строки«а»,«д»и«с» ? – vacawama
@vacawama, если я выбираю строки «a», «d», «c» ... в следующем UITableView, я могу видеть эти параметры, но как заголовки. На самом деле он работает с одним параметром, но idk, почему, когда я пытаюсь включить больше разделов (заголовков), он дает ошибку. – Joe
Ваша проблема в том, что 'selectedRows' является массивом' NSIndexPath'. Вы не можете использовать это для индексации в свой массив. Похоже, вам нужно передать массив строк на ваш второй контроллер представлений вместо того, чтобы просто установить одну строку? Это верно? – vacawama