所以我有2个视图控制器:“SpillereViewController”和“HovedViewController”。
在“SpillereViewController”中我有一个如下所示的数组:
"response": {
"players": [
{
"steamid": "99999999999999999",
"communityvisibilitystate": 3,
"profilestate": 1,
"personaname": "Something",
"lastlogoff": 1437554243,
"profileurl": "http://steamcommunity.com/id/Something/",
"avatar": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/a4/a4a54b1e0a8b0b3b85b87f9e38fde784b3ce322d.jpg",
"avatarmedium": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/a4/a4a54b1e0a8b0b3b85b87f9e38fde784b3ce322d_medium.jpg",
"avatarfull": "https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/a4/a4a54b1e0a8b0b3b85b87f9e38fde784b3ce322d_full.jpg",
"personastate": 0,
"realname": "tom",
"primaryclanid": "103582791438339107",
"timecreated": 1084138831,
"personastateflags": 0,
"loccountrycode": "US",
"locstatecode": "FL",
"loccityid": 1020
}
]
}
如何在另一个名为“HovedViewController”的视图控制器中访问该数组?
答案 0 :(得分:0)
在班级HovedViewController
中创建一个属性,如:
class HovedViewController {
var mineSpillere = [String]()
}
SpillereViewController
类中的
class SpillereViewController {
var mineSpillere = ["1", "2"]
func assignArray() {
let obj = HovedViewController()
obj.mineSpillere = self.mineSpillere
}
}
答案 1 :(得分:0)
您应该将数组传递到目标视图控制器,在您的情况下是HovedViewController。在HovedViewController中定义一个数组并添加一个segue给出一个segue标识符名称,这样你就可以使用prepareForSegue方法传递你的数组了。
override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) {
if segue!.identifier == "toHovedViewController" {
let viewController: HovedViewController = segue!.destinationViewController as ViewController
viewController.destionationArray = array
}
}