我希望在我的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];
}
}
当用户按下操作表上的“是”按钮时,我希望当前视图消失。
答案 0 :(得分:1)
// 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];
答案 1 :(得分:1)
我需要一直回到导航堆栈中的第一个(或根)视图。
我需要做的就是使用这种方法:
[controller.navigationController popToRootViewControllerAnimated:YES];
答案 2 :(得分:0)
显示和关闭视图控制器的另一种方法是使用pushViewController和popViewController。
显示viewController:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; //使用水平幻灯片过渡。如果视图控制器已经在堆栈中,则无效。
并解雇:
- (UIViewController *)popViewControllerAnimated:(BOOL)动画; //返回弹出的控制器。