如何在调用视图之前加载tableview?

时间:2015-10-29 12:45:39

标签: ios swift uitableview afnetworking-2

我想把我朋友的桌子名字放在第一位。但为什么我的视图应该先加载,然后开始执行代码

  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
    }

0 个答案:

没有答案