我試圖將當前用戶的用戶名保存到與另一個用戶關聯的數組,但ACL不允許將數據寫入另一個用戶對象。該代碼讓您輸入用戶名,如果用戶存在,它會將該用戶名添加到您關注的用戶數組中。當您開始關注用戶時,您的用戶名需要添加到您剛剛關注的人的關注者陣列中。我怎樣才能做到這一點?將數據保存到另一個用戶對象
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == 1) {
UITextField *alertTextField = [alertView textFieldAtIndex:0];
self.username = alertTextField.text;
PFQuery *query = [PFUser query];
[query whereKey:@"username" equalTo:self.username];
PFUser *user = (PFUser *)[query getFirstObject];
NSLog(@"User: %@", user[@"username"]);
if (!(user[@"username"] == NULL)) {
if (![self.followersList containsObject:user[@"username"]]) {
[self.followersList addObject:user[@"username"]];
[[PFUser currentUser]setObject:self.followersList forKey:@"Following"];
[[PFUser currentUser]saveInBackground];
NSMutableArray *otherUsersFollowers;
if ([user objectForKey:@"Followers"] == NULL) {
otherUsersFollowers = [[NSMutableArray alloc]init];
}
else {
otherUsersFollowers = [user objectForKey:@"Followers"];
}
[otherUsersFollowers addObject:[PFUser currentUser].username];
[user setObject:otherUsersFollowers forKey:@"Followers"];
[user saveInBackground];
[self.tableView reloadData];
}
else {
UIAlertView *alreadyFollow = [[UIAlertView alloc]initWithTitle:@"" message:@"You already follow that user." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alreadyFollow show];
}
}
else {
UIAlertView *noUserAlert = [[UIAlertView alloc]initWithTitle:@"" message:@"That user does not exist" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[noUserAlert show];
}
}
}
這個工作除了它創建一個名爲「追隨者」的新列。我已經有一個名爲「追隨者」的數組列,我想用我的otherUsersFollowers填充NSMutableArray – raginggoat
沒關係。 「追隨者」只需要大寫。 – raginggoat