zoukankan      html  css  js  c++  java
  • ios UI 之间的切换方法,using prepareForSegue and not

    1, use prepareForSegue:
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        RWTDetailViewController *detailController =segue.destinationViewController;
        RWTScaryBugDoc *bug = [self.bugs objectAtIndex:self.tableView.indexPathForSelectedRow.row];
        detailController.detailItem = bug;
    }
    
    
    2, use prepareForSegue:
    If you want to programmatically invoke a push segue, you give the segue a "storyboard id" in Interface Builder and then you can:
    [self performSegueWithIdentifier:"pushToMyVC" sender:self];
    
    
    
    
    3, without prepareForSegue:
    Alternatively, if you don't want to perform the segue, you can instantiate the destination view controller and then manually push to that view controller. All you need to do is to make sure that the destination view controller has its own "storyboard id" in Interface Builder, then you can:
    
    
    UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"DestinationController"];
    [self.navigationController pushViewController:controller animated:YES];
    
    
    You said "push" (and hence I used pushViewController above). If you really meant to "present a modal view controller", then that second line is:
    
    
    [self presentViewController:controller animated:YES completion:nil];
    
    
    As you can see, you don't have to use prepareForSegue to push to new scene. You only use prepareForSegue if you want to pass information to the destination view controller. Otherwise it is not needed.
    Clearly, if you're not using storyboards (e.g., you're using NIBs), then the process is entirely different. But I assume you're not using NIBs because prepareForSegue is not applicable in that environment. But if you were using NIB, it would be as follows:
    
    
    SecondViewController *controller = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    [self.navigationController pushViewController:controller animated:YES];
    
    
     
     
  • 相关阅读:
    IIS调试技术之 Debug Diagnostic (调试诊断)
    其实,你什么都不用怕
    应用程序出现挂死,.NET Runtime at IP 791F7E06 (79140000) with exit code 80131506.
    LR_问题_如何将场景中的用户设置为百分比形式
    LR_问题_脚本运行时提示没有参数化
    LR_问题_无法打开IE浏览器、监视服务器资源
    LR_问题_运行场景时提示scripts you are running in invalid
    收集好用的在线调试工具
    es2015 解构赋值
    shim和polyfill
  • 原文地址:https://www.cnblogs.com/welhzh/p/4324978.html
Copyright © 2011-2022 走看看