0
我想從我的朋友頁面中刪除朋友,但沒有成功,有人可以幫忙嗎?在Parse.com中刪除朋友iOS Objective C
.H
@property (nonatomic, strong) PFRelation *friendsRelation;
@property (nonatomic, strong) NSArray *friends;
@property (nonatomic, strong) NSMutableArray *unfriend;
@property (nonatomic, strong) PFUser *currentUser;
.M
self.friendsRelation = [[PFUser currentUser] objectForKey:@"friendsRelation"];
PFQuery *query = [self.friendsRelation query];
[query orderByAscending:@"username"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
if (error) {
// NSLog(@"error %@ %@", error, [error userInfo]);
} else {
self.friends = objects;
[self.tableView reloadData];
}
}];
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
PFUser *user = [self.friends objectAtIndex:[self.tableView indexPathForSelectedRow]];
PFRelation *friendsRelation = [self.currentUser relationForKey:@"friendsRelation"];
if(0 == buttonIndex){ //cancel button
} else if (1 == buttonIndex){
if ([self isFriend:user]) {
for (PFUser *friend in self.friends) {
if ([friend.objectId isEqualToString:user.objectId]) {
[self.unfriend removeObject:friend];
break;
}
}
[friendsRelation removeObject:user];
} else {
}
[self.currentUser saveInBackgroundWithBlock:^(BOOL succeed, NSError *error) {
if (error) {
NSLog(@"error %@ %@", error, [error userInfo]);
}
}];
}
[self.tableView reloadData];
}
-(BOOL)isFriend:(PFUser *)user
{
for (PFUser *friend in self.friends) {
if ([friend.objectId isEqualToString:user.objectId]) {
return YES;
}
}
return NO;
}
的可變數組是有添加和刪除對象,但目前其空我想這就是爲什麼它不工作? 當我按下確定我想從我的freindsRelation中刪除朋友,但此刻沒有任何事情發生。
我該怎麼做?因爲我們無法從數組中添加和刪除 – Joey121
將其更改爲可變,並在獲得結果時製作可變副本。 – Wain
嗨,謝謝,用戶刪除,但當我回到頁面時,它再次顯示 – Joey121