【问题标题】:Action sheet cancel button not cancelling action sheet操作表取消按钮不取消操作表
【发布时间】:2014-08-14 10:19:17
【问题描述】:

我将一个数组(来自数据库)传递给操作表。我添加了取消按钮,但它没有取消。它显示错误数组超出范围。这是我的代码:

UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Chatting Apps" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];

    for (int i =0;i<self.arrOfAppNames.count;i++) {

        [actionSheet addButtonWithTitle:[[self.arrOfAppNames objectAtIndex:i]objectAtIndex:1]];

    }
    [actionSheet addButtonWithTitle:@"Cancel"];
    actionSheet.cancelButtonIndex = [self.arrOfAppNames count];
    [actionSheet showInView:self.view];

【问题讨论】:

  • 只需从[actionSheet addButtonWithTitle:[[self.arrOfAppNames objectAtIndex:i]objectAtIndex:1]]; 行中删除objectAtIndex:1
  • @SweetAngel 你是对的,这是这个问题的解决方案。你必须把它作为你的答案。如果你想放,我会删除我的答案
  • 谢谢... :) @MohitPopat

标签: ios objective-c uiactionsheet uiactionsheetdelegate


【解决方案1】:

当我将 Cancel 按钮添加到操作表时,这对我有用:

[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = actionSheet.numberOfButtons - 1;

【讨论】:

  • 它仍然无法正常工作。取消按钮在那里显示,但是当我点击它时,应用程序因错误数组超出范围而崩溃
  • 如果您的应用在点击取消按钮后崩溃,那么听起来问题可能出在应用处理取消点击的方式上。您可能想查看UIActionSheetDelegate 方法的代码。
【解决方案2】:

使用此代码希望对您有所帮助:

UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:@"Chatting Apps" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles: nil];

for (int i =0;i<self.arrOfAppNames.count;i++) {

    [actionSheet addButtonWithTitle:[[self.arrOfAppNames objectAtIndex:i]objectAtIndex:1]];

}
[actionSheet addButtonWithTitle:@"Cancel"];
actionSheet.cancelButtonIndex = (int)[self.arrOfAppNames count];
[actionSheet showInView:self.view];

【讨论】:

  • 它仍然无法正常工作。取消按钮在那里显示,但是当我点击它时,应用程序因错误数组超出范围而崩溃
  • 在设置cancelButtonIndex和uiactionsheet委托方法nslog buttonindex之前请nslog [self.arrOfAppNames count]
  • @AmitLimje 你听过甜蜜天使所说的吗?
  • @MohitPopat 甜天使说的是对的,但我正在从数据库中获取数组。因此我就这样做了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多