1
我有一個列出來自各種用戶的註釋的UITableView。我將所有評論保存到Core Data。我也實現了NSFetchedResultsController。評論的其中一個屬性是用戶名 - 發表評論的用戶。根據該單元格中數據的屬性值僅刪除特定的UITableViewCell
我只希望用戶能夠刪除自己的評論。這裏是我的代碼:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
//Only be able to delete user generated cells
Comment *comment = [[self fetchedResultsController]objectAtIndexPath:indexPath];
if (comment.username != self.username) {
return NO;
}
return YES;
}
performfetch被稱爲viewDidLoad中
當CommentsViewController被加載並創造了新的註釋,該功能可以運行。但是,如果以前有任何評論,即使用戶創建了這些評論,也不能編輯這些評論。
關於可能會發生什麼的任何想法?
啊!!腦屁。謝謝@danh! – djblue2009