[英]Show or dismiss a specific ViewController after performing an action
I want to show a specific ViewController (or dismiss) a View after performing an IBAction in my iPhone App. 我想在我的iPhone应用程序中执行IBAction后显示特定的ViewController(或关闭)View。 I've tried
我试过了
[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];
However this does not appear to do anything once the action has been performed. 但是,一旦执行了该操作,这似乎就没有做任何事情。
A bit more information: 更多信息:
-(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];
}
}
I want the current view to disappear when a user presses the Yes button on the actionsheet. 当用户按下操作表上的“是”按钮时,我希望当前视图消失。
// 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];
I needed to go all the way back to the first (or, root) view in my navigation stack. 我需要一直回到导航堆栈中的第一个(或根)视图。
All I need to do was use this method: 我需要做的就是使用这个方法:
[controller.navigationController popToRootViewControllerAnimated:YES];
Another way to show and dismiss a view controller is with pushViewController and popViewController. 另一种显示和关闭视图控制器的方法是使用pushViewController和popViewController。
To show a viewController: 要显示viewController:
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated; // Uses a horizontal slide transition.
//使用水平幻灯片过渡。 Has no effect if the view controller is already in the stack.
如果视图控制器已在堆栈中,则无效。
And to dismiss: 并解雇:
-(UIViewController *)popViewControllerAnimated:(BOOL)animated; - (UIViewController *)popViewControllerAnimated:(BOOL)动画; // Returns the popped controller.
//返回弹出的控制器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.