联系人未在swift中第一次显示

时间:2015-08-26 11:23:46

标签: ios swift uitableview abaddressbook

当我尝试使用联系人列表加载表格视图时,它第一次没有显示。但是,如果我尝试Pull-To-Refresh或者转到某个视图并返回到表视图控制器,则联系人正在加载并完美显示。这是代码:

func getContactNames()
{    
    let allContacts = ABAddressBookCopyArrayOfAllPeople(addressBookRef).takeRetainedValue() as Array
    for record in allContacts {
        let currentContact: ABRecordRef = record
        let currentContactName = ABRecordCopyCompositeName(currentContact)?.takeRetainedValue()
            as? String

        if(currentContactName != nil) {
            self.arrFriendsList.append(currentContactName! as String)
        }
    }

    // For alphabatically arranging
    self.arrFriendsList = self.arrFriendsList.sorted { $0.localizedCaseInsensitiveCompare($1) == NSComparisonResult.OrderedAscending }

    self.arrFilteredTableData = self.arrFriendsList
    self.tblView.reloadData()
}

我在viewDidLoad方法中调用此函数。有什么解决方案吗?在此先感谢:)

0 个答案:

没有答案