objective-c - 执行操作后显示或关闭特定的 ViewController

标签 objective-c ios uitableview

我想在我的 iPhone 应用程序中执行 IBAction 后向特定的 ViewController 显示(或关闭) View 。我试过了

[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];

然而,一旦执行了操作,这似乎没有任何作用。

更多信息:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

{
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
    if (selectedCell.tag == 1)
    {

        UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                      initWithTitle:@"Are you sure you want to delete this project?"
        delegate:self cancelButtonTitle:@"No" destructiveButtonTitle:@"Yes, I’m Sure" otherButtonTitles:nil];
        [actionSheet showInView:self.view];


    }

}

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != [actionSheet cancelButtonIndex])
    {

        [self.tableView beginUpdates]; // Avoid  NSInternalInconsistencyException

        // Delete the project object that was swiped
        Project *projectToDelete = self.project;
        NSLog(@"Deleting (%@)", projectToDelete.name);
        [self.managedObjectContext deleteObject:projectToDelete];
        [self.managedObjectContext save:nil];

    }
}

我希望当前 View 在用户按下操作表上的"is"按钮时消失。

最佳答案

// Assume we are inside a UIViewController (or a subclass)

DestinationController *destinationController = [[DestinationController alloc] init];
[self presentModalViewController:destinationController animated:YES];

...

// Assume we are now in destination controller

// Dismiss
[self dismissModalViewControllerAnimated:YES];

关于objective-c - 执行操作后显示或关闭特定的 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9787243/

相关文章:

ios - 有没有像 UIPopOverController 这样的 API

uitableview - 嵌套 TableView 不再适用于 iOS 7

ios - 返回 block 的方法

iphone - 了解 Objective-C 范围问题

ios - itunes connect - beta 权限缺失错误

ios - iTunesConnect 无法接受邀请 - 无效年份

swift - 在 tableView 中放置一个 UIButton

iphone - 调整标签在 UITableViewCell 中的位置

iphone - IOS 中的单元测试

objective-c - NSValueTransformer 没有被调用