【问题标题】:Navigate to UITableViewController by selecting UITableView Cell通过选择 UITableView Cell 导航到 UITableViewController
【发布时间】:2013-09-12 21:23:15
【问题描述】:

我正在使用UITableView 没有导航控制器。我的问题是,当我单击特定单元格时,它不会推送到另一个 UIViewController

这是我的代码,

-(void)goToMyView
{
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
TOMenuViewController *vc = [sb instantiateViewControllerWithIdentifier:@"MyViewController"];
[self.navigationController pushViewController:vc animated:YES];
}

如何移动到另一个视图控制器并从中返回。

【问题讨论】:

    标签: iphone ios uitableview uinavigationcontroller


    【解决方案1】:

    而不是这行代码:

    [self.navigationController pushViewController:vc animated:YES];
    

    使用这行代码:

    [self presentViewController:vc animated:YES completion:nil];
    

    当您想在新视图控制器中返回旧视图控制器时:

    [self dismissViewControllerAnimated:YES];
    

    对于动画,在您展示视图控制器之前使用:

      vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    

    【讨论】:

    • 感谢您的帮助,但它的动画是从下到上的。我需要从右到左。
    • @user2745507 你想要不同的动画吗?
    • @user2745507 请记住这个答案是否有助于检查。
    【解决方案2】:

    尝试使用 prepareForSegue:

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
        //you have to give an id to segue, in storyboard
    
       if ([[segue identifier] isEqualToString:@"detail"]) {
    
         //passing strings or whatever you want here so:
        [segue.destinationViewController setStringDetail: yourString]; 
    
     }
    

    在 detailViewController 中自动创建后退按钮

    【讨论】:

      【解决方案3】:

      在此处查看我的答案,如何将模态转场的动画更改为看起来像推送转场。

      Pushing a view to a UINavigationController that's not in the same view hierarchy

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-10-23
        • 2015-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多