2015-09-01 21 views
-1

我已經上傳Parse.com的User類中的另一個數組列,並且我想要將該數組返回並將其顯示在表視圖中。該陣列是用戶輸入的阻止用戶列表。檢索數組並在tableView中顯示iOS Parse.com

NSString *usernameBlock = [self.blockUser.text]; 

PFUser *blockedUser = [PFUser currentUser]; 
[blockedUser addObject:usernameBlock forKey:@"blockedUsers"]; 
self.blockedRelation = [blockedUser relationForKey:@"blocked"]; 
[blockedUser saveInBackground]; 

這增加了另一個數組列的用戶名。

現在在我的blockedUserVC我想查詢該列並獲得數組顯示在tableView中。

我曾嘗試以下,但我不斷收到崩潰: -

//tried this 
PFQuery *query = [PFQuery queryWithClassName:@"_User"]; 
[query whereKey:@"blockedUsers" equalTo:[PFUser currentUser]]; 
[query valueForKey:@"blockedUsers"]; 
[query whereKey:@"blockedUsers" containedIn:_blockedUser]; //blocked user is an array 
[query orderByAscending:@"username"]; 
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){ 
    if (error) { 
     // NSLog(@"error %@ %@", error, [error userInfo]); 
    } else { 
     self.blockedUser = objects; //blockedUser is an array 
     [self.tableView reloadData]; 
    } 
}]; 

我應該怎麼查詢,所以我得到這個數組?

crashlog: 
    Terminating app due to uncaught exception 'NSUnknownKeyException', reason: 
'[<PFQuery 0x7fc13150fbe0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key blockedUsers.' 
+0

如果你說你正在崩潰而你沒有說我們該怎麼幫忙? – Fogmeister

+0

@Fogmeister它說空返回,所以它崩潰 – smithyy

+0

請複製並粘貼崩潰日誌。它有助於診斷事故。 – Fogmeister

回答

1
[query valueForKey:@"blockedUsers"]; 

此行是導致飛機失事的原因,使用包括代替。 https://parse.com/docs/ios/guide

另外,我覺得這樣的:

[query whereKey:@"blockedUsers" containedIn:_blockedUser]; //blocked user is an array 

應該是:

[query whereKey:@"blockedUsers" containsAllObjectsInArray:@[_blockedUser]]; //blocked user is an array 

這不會導致崩潰,但它會屈服於(從我的理解)錯誤的結果。

+0

的崩潰日誌感謝但沒有用戶顯示在我的表中? – smithyy

+0

這可能是另一個問題,爲此打開另一個問題。您上面的代碼僅用於檢索數據。但是,請確保您已在UITableViewController類中正確實現了委託和數據源方法,並確保您使用的是要顯示的數據。 – RJiryes

+0

'[query whereKey:@「blockedUsers」containsAllObjectsInArray:@ [_ blockedUser]]; //被阻止的用戶是一個數組 '這一行導致崩潰 – smithyy

相關問題