0

场景:我正在尝试实现类似于 iPhone 的联系人簿应用程序来删除联系人。在 iPhone 的通讯录应用程序中,要删除联系人,可以进入“所有联系人”场景并单击联系人(例如“测试删除”),然后单击“编辑”按钮并向下滚动以找到“删除”按钮。单击“删除”按钮后,会显示带有“删除”和“取消”按钮的 UIActionSheet,可以单击“删除”删除联系人,并且联系人应用程序会自动返回“所有联系人”场景。

问题:在我的应用程序中,我添加了一个“删除”按钮和启动 UIActionSheet 的代码:

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

并添加委托:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"actionSheet is called: clicked button - %ld, %@", (long)buttonIndex, [self.parentViewController description]); }

这些都工作正常。就像联系人应用程序一样,这是在“编辑”场景中删除一个项目,我想从这个“编辑”场景转换回“所有项目”场景,将正在编辑的项目从“全部”中删除物品的场景。我不知道如何进行过渡——这就是问题所在。

问题:如何实现委托(或其他任何东西),以便我的应用程序就像 iPhone 的联系人应用程序一样从“编辑”场景转换回“所有联系人”场景?

有什么想法吗?

4

1 回答 1

0

尝试使用以下代码

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == actionSheet.destructiveButtonIndex) /// here you can get destructiveButton tapped
    {
         [self.navigationController popToRootViewControllerAnimated:YES]; // and got to previous viewController;
    }
}
于 2013-09-05T13:34:24.340 回答