下面是我刪除的代碼,它工作正常,但您必須打開另一個選項卡,然後再次單擊此選項卡才能移除該項目。因爲這不是普通的UITableView,所以你不能從數組中移除然後更新表。所以有人可以幫助我刷新視圖。另外下面的代碼片段不起作用:從UITableView刪除行
// Reload the view completely
if ([self isViewLoaded]) {
self.view=nil;
[self viewDidLoad];
}
這裏是我的刪除代碼:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// If row is deleted, remove it from the list.
if (editingStyle == UITableViewCellEditingStyleDelete){
// Delete song from list & disc \\
//Remove from arrays
[self.Writer removeObjectAtIndex:[indexPath row]];
[self.Book removeObjectAtIndex:[indexPath row]];
[self.BookImageId removeObjectAtIndex:[indexPath row]];
NSString *TempWriter = [self.ArtistNamesArray componentsJoinedByString:@","];
NSString *TempBook = [self.SongNamesArray componentsJoinedByString:@","];
NSString *TempBookImageId = [self.YoutubeIDSArray componentsJoinedByString:@","];
TempWriter = [TempWriter substringToIndex:[TempArtistNames length] - 1];
TempBook = [TempBook substringToIndex:[TempSongNames length] - 1];
TempBookImageId = [TempBookImageId substringToIndex:[TempYouTube length] - 1];
//Save Details
[[NSUserDefaults standardUserDefaults] setValue:[NSString stringWithFormat:@"%@,", TempBook] forKey:@"BookName"];
[[NSUserDefaults standardUserDefaults] setValue:[NSString stringWithFormat:@"%@,", TempWriter] forKey:@"WriterName"];
[[NSUserDefaults standardUserDefaults] setValue:[NSString stringWithFormat:@"%@,", TempBookImageId] forKey:@"ImageId"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
}
和我的viewWillAppear中的代碼是:
- (void) viewWillAppear: (BOOL) animated
{
// Reload the view completely
if ([self isViewLoaded]) {
self.view=nil;
[self viewDidLoad];
}
}
感謝所有誰可以幫助
完全正是我想要的:)乾杯兄弟 – user393273 2011-03-27 17:57:16