我想把我朋友的桌子名字放在第一位。但为什么我的视图应该先加载,然后开始执行代码
self.art = [responseObject]
let jsonArrays :[String:AnyObject] = self.art.firstObject as! Dictionary
let name = jsonArrays["response"]
for var value in name as! NSArray
{
value = (name?.valueForKey("first_name"))!
self.friends = [value]
}
这是完整的代码
class TableViewController: UITableViewController
{
let manager = AFHTTPRequestOperationManager()
let url = "https://api.vk.com/method/friends.get"
var dict = NSDictionary()
var art = []
var friends = NSArray()
var arrayUser = NSArray()
var ar = []
override func viewDidLoad() {
super.viewDidLoad()
self.getFriends()
self.friends = NSArray()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func getFriends()
{
dict = ["user_id":"107487867",
"name":"order",
"count":5,
"fields":"photo",]
self.manager.GET(url, parameters: dict,
success:{ (operation:AFHTTPRequestOperation,
responseObject: AnyObject!) in
self.art = [responseObject]
let jsonArrays :[String:AnyObject] = self.art.firstObject as! Dictionary
let name = jsonArrays["response"]
for var value in name as! NSArray
{
value = (name?.valueForKey("first_name"))!
self.friends = [value]
}
}){ (operation:AFHTTPRequestOperation!, NSError) -> Void in
}
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return friends.count
}