从UITableView删除行 [英] Delete Rows from UITableView

查看:90
本文介绍了从UITableView删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我删除的代码,它可以正常工作,但是您必须打开另一个选项卡,然后再次单击此选项卡才能删除该项目.由于这不是普通的UITableView,因此您不能仅从数组中删除然后更新表.所以有人可以帮我刷新视图.另外,以下代码段也无效:

Here is the code for my delete, it works fine but you have to open another tab and then click this tab again for the item to be removed. As this is not the normal UITableView you cannot just remove from array and then update table. so could someone please help me refresh the view. Also the snippet below does not work:

// 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代码是:

and my ViewWillAppear code is:

- (void) viewWillAppear: (BOOL) animated
{
    // Reload the view completely
    if ([self isViewLoaded]) {
        self.view=nil;
        [self viewDidLoad];
    }

}

感谢所有将提供帮助的人

Thanks for all who will help

推荐答案

您似乎没有在呼叫

You don't appear to be calling the UITableView reloadData method at any point after you've carried out the deletion.

因此,添加...

[tableView reloadData];

...在- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath方法的底部应该可以解决问题.

...to the bottom of your - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath method should solve the problem.

这篇关于从UITableView删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆