如何在iphone中从网格视图中删除图像后刷新网格视图

时间:2012-12-18 13:45:27

标签: iphone objective-c ios xcode

我已将图像保存在@“/ Documents / MyApp%d.png中,我有一个NSMutableArray,其中我设置了整数值。例如我的NSMutableArray包含(2,3,5,6,7,12,14) ,16)现在在网格中它将显示MyApp2,MyApp3,MyApp5等(来自数组)。这是我的网格视图 enter image description here

假设我点击gridview的第三个索引,即MyApp5,然后在swipeView中打开。 像这样 enter image description here

当我点击删除图标时,它将删除此图像。记得我在nsmutablearray中有过(2,3,5,6,7,12,14,16)。当我删除此图像时,我的值更改为此(2,3,6,7,12,14,16),这意味着它已成功删除,但当我再次返回网格视图时,它显示为这样。 enter image description here

我不知道我哪里错了。但当我回去再次回到网格视图时,它将正确显示所有图像。

我将此代码用于gridView link

2 个答案:

答案 0 :(得分:0)

该项目中的UIGridViewUITableView的子类。您是否尝试向其发送reloadData消息?

此外,Apple保留UI前缀(以及所有其他双字母前缀)。使用不是来自Apple的名为UIGridView的类是危险的。

答案 1 :(得分:0)

尝试获取如下的cellIdentifier; (define int reloader) 然后,当您需要重新加载tableview时,请尝试增加重新加载器。 我在下面写了我的reloadData函数,你可以使用它。

-(NSString *) getCellIdentifier:(NSInteger)index sectionindex:(NSInteger)section{
    return [[[NSString stringWithFormat:@"%i",section] stringByAppendingFormat:@"%i" , index] stringByAppendingFormat:@"%i", reloader];
}

- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellIdentifier = [self getCellIdentifier:indexPath.row sectionindex:indexPath.section];
    cell= [tableView dequeueReusableCellWithIdentifier:cellIdentifier]
    if (cell == nil) {
        cell = [[Cell alloc] init];
    }

    cell.label.text = [NSString stringWithFormat:@"(%d,%d)", rowIndex, columnIndex];

    return cell;
}

-(void) reloadData{
    reloader++;
    [tableView reloadData];
}