ios tableView如何彻底删除cell
比如删了北京以后,我回到了先前一个页面,再回到这个tableView的时候,北京还在。如何彻底删除cell?这是代码-(NSMutableArray*)cityWeath...
比如删了北京以后,我回到了先前一个页面,再回到这个tableView的时候,北京还在。如何彻底删除cell?
这是代码
- (NSMutableArray *)cityWeather
{
if (self.city == nil)
self.city = [[NSMutableArray alloc] initWithObjects:@"北京",@"上海",@"广州",@"深圳",@"重庆",@"厦门",@"香港",@"福州",@"郑州",@"西安",@"成都",nil];
return _city;
}
- (NSInteger)tableView:(UITableView *)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 展开
这是代码
- (NSMutableArray *)cityWeather
{
if (self.city == nil)
self.city = [[NSMutableArray alloc] initWithObjects:@"北京",@"上海",@"广州",@"深圳",@"重庆",@"厦门",@"香港",@"福州",@"郑州",@"西安",@"成都",nil];
return _city;
}
- (NSInteger)tableView:(UITableView *)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 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询