Это мой код в быстройАнализировать findObjectsInBackgroundWithBlock возвращения ноля
class UserViewController: UITableViewController {
var userArray: NSMutableArray = []
@IBOutlet weak var friendListTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
retrieveMessages()
}
func retrieveMessages() {
var query = PFUser.query()
if let username = PFUser.currentUser().username {
query.whereKey("username", equalTo: username)
query.findObjectsInBackgroundWithBlock {
(objects, error) -> Void in
for object in objects! {
let usernames:String? = (object as PFObject)["Friends"] as? String
println(usernames)
if usernames != nil {
self.userArray.addObject(usernames!)
}
}
dispatch_async(dispatch_get_main_queue()) {
self.friendListTableView.reloadData()
}
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return userArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// Update - replace as with as!
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = userArray[indexPath.row] as? String
return cell
}
проблема является метод возврата findObjectsInBackgroundWithBlock ноля так что моя таблица не будет обновляться, объект содержит массив друзей, что текущий пользователь имел. Итак, как я могу это исправить? спасибо заранее и дайте мне знать, если вам нужна дополнительная информация!
Обновление: Я изменить свой код (я использую Xcode 6,2)
class UserTableViewController: UITableViewController {
var userArray: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
retrieveMessages()
}
func retrieveMessages() {
var query = PFUser.query()!
if let username = PFUser.currentUser()!.username {
query.whereKey("username", equalTo: username)
query.findObjectsInBackgroundWithBlock { [weak self]
(objects, error) -> Void in
println(objects)
for object in objects! {
let username:String? = (object as PFUser).username
if username != nil {
self!.userArray.append(username!)
}
}
self!.tableView.reloadData()
}
}
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return userArray.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("userCell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = userArray[indexPath.row]
return cell
}
и мой крах приложения, это журнал ошибок
2015-06-08 1:41 : 32.944 ParseStarterProject [635: 14183] Неизвестный класс _TtC19ParseStarterProject18UserViewController в файле Interface Builder. 2015-06-08 01: 41: 32.966 ParseStarterProject [635: 14183] * Завершение приложения из-за неперехваченного исключения «NSUnknownKeyException», причина: «[setValue: forUndefinedKey:]: этот класс не является ключевым значением, совместимым с кодировкой для ключ friendListTableView. ' * Первый стек вызовов броска: ( 0 CoreFoundation 0x000000010d35fa75 exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010efeabb7 objc_exception_throw + 45 2 CoreFoundation 0x000000010d35f6b9 - [NSException поднять] + 9 3 Foundation 0x000000010d803d43 - [NSObject (NSKeyValueCoding) SetValue: forKey:] + 259 4 CoreFoundation 0x000000010d2a95e0 - [NSArray makeObjectsPerformSelector:] + 224 5 UIKit 0x000000010dfec4ed - [UINib instantiateWithOwner: варианты:] + 1506 6 UIKit 0x000000010de4aa88 - [UIViewController _loadViewFromNibNamed: расслоение:] + 242 7 UIKit 0x000000010de4b078 - [UIViewController loadView] + 109 8 UIKit 0x000000010e008bd8 - [UITableViewController loadView] + 76 9 UIKit 0x000000010de4b2e9 - [UIViewController loadViewIfRequired] + 75 10 UIKit 0x000000010de4b77e - [UIViewController вид] + 27 11 UIKit 0x000000010e3eef4e - [_ UIFullscreenPresentationController _setPresentedViewController:] + 65 12 UIKit 0x000000010de26d69 - [UIPresentationController initWithPresentedViewController: presentingViewController:] + 105 13 UIKit 0x000000010de57531 - [UIViewController _presentViewController: withAnimationController: завершение:] + 1 746 14 UIKit 0x000000010de59871 __62- [UIViewController presentViewController: анимированные: завершение:] _ block_invoke + 132 15 UIKit 0x000000010de59795 - [UIViewController presentViewController: анимированные: завершение:] + 229 16 ParseStarterProject 0x000000010c81c1c0 _TFC19ParseStarterProject14ViewController13viewDidAppearfS0_FSbT_ + 17 тысяча четыреста восемьдесят-восемь ParseStarterPro Ject 0x000000010c81c231 _TToFC19ParseStarterProject14ViewController13viewDidAppearfS0_FSbT_ + 49 18 UIKit 0x000000010de4f361 - [UIViewController _setViewAppearState: isAnimating:] + 567 19 UIKit 0x000000010de4feab - [UIViewController _executeAfterAppearanceBlock] + 52 20 UIKit 0x000000010dd48adb _applyBlockToCFArrayCopiedToStack + 314 21 UIKit 0x000000010dd48974 _afterCACommitHandler + 547 22 CoreFoundation 0x000000010d294507 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 23 CoreFoundation 0x000000010d294460 __CFRunLoopDoObservers + 368 24 CoreFoundation 0x000000010d28a293 __CFRunLoopRun + 1123 25 CoreFoundation 0x000000010d289bc6 CFR unLoopRunSpecific + 470 26 GraphicsServices 0x0000000110a99a58 GSEventRunModal + 161 27 UIKit 0x000000010dd25580 UIApplicationMain + +1282 28 ParseStarterProject 0x000000010c8203ae top_level_code + 78 29 ParseStarterProject 0x000000010c82048a основной + 42 30 libdyld.dylib 0x000000010f802145 старт + 1 ) LibC++ abi.dylib: оканчивающийся неперехваченным исключением типа NSException (lldb)
Обновление: исправить ошибку и это скриншоты моего разбора моего синтаксический анализ в классе «User» https://www.dropbox.com/s/6xp48v3yn0l2hje/Screen%20Shot%202015-06-03%20at%202.10.13%20PM.png?dl=0 Это я s мой список друзей моего друга в колонке «Друзья» https://www.dropbox.com/s/pd8mt8sf35u1m0v/Screen%20Shot%202015-06-03%20at%202.10.55%20PM.png?dl=0
Какое исследование вы провели? Каковы были результаты? Что означает 'println (usernames)' print? Вы проверили объект 'error'? Что это говорит? Откуда вы знаете результат * не должен * быть 'nil'? У этого пользователя есть друзья? –
Сбой кода? Потому что если результат равен нулю, объекты! должен выбросить ошибку –
@ sin90 дать некоторую информацию о том, получаете ли вы какую-либо ошибку или сбой приложений или нет ... –