比如删了
北京以后,我回到了先前一个页面,再回到这个tableView的时候,北京还在。如何彻底删除cell?
这是代码
- (NSMutableArray *)cityWeather
{
if (self.city == nil)
self.city = [[NSMutableArray alloc] initWithObjects:@"北京",@"
上海",@"广州",@"深圳",@"
重庆",@"厦门",@"
香港",@"福州",@"郑州",@"西安",@"成都",nil];
return _city;
}
- (NSInteger)tableView:(U
ITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _city.count;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete ) {
[self.city removeObjectAtIndex:indexPath.row];
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
[self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
[self.tableView reloadData];
}
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
if (sourceIndexPath != destinationIndexPath) {
id object = [self.city objectAtIndex:sourceIndexPath.row];
[self.city removeObjectAtIndex:sourceIndexPath.row];
if (destinationIndexPath.row > [self.city count]) {
[self.city addObject:object];
}
else {
[self.city insertObject:object atIndex:destinationIndexPath.row];
}
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"lpCityWeather";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
NSString *aString = [self.city objectAtIndex:indexPath.row];
cell.textLabel.text = aString;
cell.detailTextLabel.text = [self.temperature objectForKey:aString];
return cell;
}
@end
你在数据里面是不是没有删除,打下断点看一下你的数据 。 或者是你删了数据没有刷新这个界面