我只想允许用户删除评论,前提是他们是发布评论的用户。
我正在使用 canEditRowAtIndexPath: 方法并尝试以下方法。包含此条件后,删除不再显示。
if (userIdNumber == aNum) {
return YES;
}
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return YES if you want the specified item to be editable.
NSString *savedValue = [[NSUserDefaults standardUserDefaults]
stringForKey:@"userId"];
NSNumber *userIdNumber = [userId objectAtIndex:indexPath.row];
NSNumber *aNum = [NSNumber numberWithInteger: [savedValue integerValue]];
NSLog(@"savedValue is %@",savedValue);
NSLog(@"aNum is %@",aNum);
NSLog(@"userIdNumber is %@",userIdNumber);
if (userIdNumber == aNum) {
return YES;
}
else {
return NO;
}
}