Objective c 如何在ios中从NSMutableArray中删除最后一个对象而不导致应用程序崩溃

Objective c 如何在ios中从NSMutableArray中删除最后一个对象而不导致应用程序崩溃,objective-c,iphone,nsmutablearray,Objective C,Iphone,Nsmutablearray,这是我的密码 (void)viewDidLoad { descriptionArray = [[NSMutableArray alloc] initWithObjects:@"I'm not perfect,imake mistakes,i hurt people. But when i say sorry,i really mean it.", @"Sing

这是我的密码

 (void)viewDidLoad

{
    descriptionArray = [[NSMutableArray alloc] initWithObjects:@"I'm not perfect,imake mistakes,i hurt people. But when i say sorry,i really mean it.",
                                                               @"Single",
                                                               @"jon@live.com",
                                                               @"+91 9731244748",
                                                               @"jon.Korta",
                                                               @" 05 Common Friends",
                                                               @"Facebook", nil];

}
在UITableView数据源方法中

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{
 static NSString *cellidentifier = @"CellID";

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:cellidentifier];

    if (cell == nil)

    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];

     cell.descriptionLbl.text = [descriptionArray objectAtIndex:indexPath.row];

}

return cell;
}
CustomCell.h

@property (strong, nonatomic) IBOutlet UILabel *descriptionLbl;
我使用CustomCell在UITableView单元格中显示descriptionArray对象。我想从descriptionArray中删除UITableView单元格中的“Facebook”对象。
任何人都可以指导我。提前感谢

如果您真的想从阵列中删除最后一个对象,只需执行以下操作

[descriptionArray removeObjectAtIndex:descriptionArray.count-1];


并确保单元格数量应为descriptionArray.count-1

如果确实要从数组中删除最后一个对象,只需执行以下操作

[descriptionArray removeObjectAtIndex:descriptionArray.count-1];


并且确保单元格的数量应该是
descriptionArray。count-1

因为您使用
descriptionArray
作为
cellForRow
方法的数据源,所以需要确保
numberOfRow
也返回数组计数。因此,当您删除数组中的最后一个对象并调用table reload data时,它不会崩溃。

由于您使用
descriptionArray
作为
cellForRow
方法的数据源,您需要确保
numberOfRow
也返回数组计数。因此,当您删除数组中的最后一个对象并调用table reload data时,它不会崩溃。

您可以使用
[descriptionArray RemovelasObject]删除最后一个对象
删除最后一个元素后,需要重新加载表视图。不要忘记重新加载表视图。

您可以使用
[descriptionArray RemovelAsObject]删除最后一个对象
删除最后一个元素后,需要重新加载表视图。不要忘记重新加载表视图。

1)格式化代码。2) 为什么会崩溃?(引发了什么异常?)3)删除条目的代码在哪里?[descriptionArray RemovelasObject];由于未捕获的异常“NSRangeException”而终止应用程序,原因:“***-[\uu NSArrayM objectAtIndex:]:索引6超出边界[0..5]”我在我的代码
NSMutableArray
中获得此异常,有方法删除最后一个对象
[descriptionArray RemovelasObject]您可以使用它。简单地使用它来删除最后一个对象-[descriptionArray RemovelAsObject]或[descriptionArray removeObjectAtIndex:descriptionArray.count-1];1) 格式化你的代码。2) 为什么会崩溃?(引发了什么异常?)3)删除条目的代码在哪里?[descriptionArray RemovelasObject];由于未捕获的异常“NSRangeException”而终止应用程序,原因:“***-[\uu NSArrayM objectAtIndex:]:索引6超出边界[0..5]”我在我的代码
NSMutableArray
中获得此异常,有方法删除最后一个对象
[descriptionArray RemovelasObject]您可以使用它。简单地使用它来删除最后一个对象-[descriptionArray RemovelAsObject]或[descriptionArray removeObjectAtIndex:descriptionArray.count-1];