Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.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 var=string[indexpath.row],prepareforsgue,调用字符串作为导航条标题(swift)_Ios_Swift - Fatal编程技术网

Ios var=string[indexpath.row],prepareforsgue,调用字符串作为导航条标题(swift)

Ios var=string[indexpath.row],prepareforsgue,调用字符串作为导航条标题(swift),ios,swift,Ios,Swift,第二视图控制器: override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if(segue.identifier == "packtofeedsegue"){ let indexPath = self.tableView.indexPathForSelectedRow() var lastviewed = userids[indexPath!.row]

第二视图控制器:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if(segue.identifier == "packtofeedsegue"){
        let indexPath = self.tableView.indexPathForSelectedRow()
        var lastviewed = userids[indexPath!.row]
        println(lastviewed)
    }
}
我正在尝试
preparesegue
将一个变量设置为行文本,然后在下一个视图控制器中调用该文本作为导航栏的标题

Im获取:
无法将[(字符串)]类型的值分配给字符串值?对于self.navigationController.navigationBar.topItem.title=lastviewed


当我将
var lastviewed=[String]()
更改为
var lastviewed=String()
时,没有错误,但什么也没有显示:println显示了正确的文本,因此正确的信息进入了
prepareforsgue
[String]
意味着“类型为
String
的对象数组”。您需要的是
字符串

var lastviewed = [String]()

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationController.navigationBar.topItem.title = lastviewed
}
将标题配置放入
视图将出现
。这应该足够了

var lastViewed = ""
prepareforsgue
中分配给视图控制器:

self.title = lastViewed

我试过了。在我的帖子底部提到了这一点。对不起,我没有。我需要为第二个viewcontroller设置特定的类还是以特定的方式连接viewcontroller???,因为当我在第二个viewcontroller上打印LN(lastviewed)时,什么都不会出现是的。第二个视图控制器应具有包含变量的自定义类(在Interface Builder中设置)。您必须从segue.destinationViewController中强制转换视图控制器。感谢您的帮助,您最好不要让任何人告诉您其他情况。上次查看的是字符串列表还是单个字符串?
let destination = segue.destinationViewController as! SecondController
destination.lastViewed = userIds[indexPath!.row]!