Segue from one storyboard to a different storyboard?

前端 未结 9 1895
孤独总比滥情好
孤独总比滥情好 2020-12-13 18:43

I have too many views on one storyboard which is causing it to run really slow. I have been told that a solution to this issue would be to split the one storyboard into mult

相关标签:
9条回答
  • 2020-12-13 18:59

    Here is a simple Swift solution:

        let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ViewController") as UIViewController
        // .instantiatViewControllerWithIdentifier() returns AnyObject! this must be downcast to utilize it
    
        self.presentViewController(viewController, animated: false, completion: nil)
    
    0 讨论(0)
  • 2020-12-13 19:05

    With Xcode 7 you can pick Storyboard References

    and set the destination storyboard and controller

    0 讨论(0)
  • 2020-12-13 19:10

    Another solution using segues (iOS SDK 6.0+), which keeps code separated by purpose and leaves room for customisation:

    - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
        //check/validate/abort segue
        return YES;
    }//optional
    
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        //sender - segue/destination related preparations/data transfer
    }
    
    #pragma mark - Table view delegate
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        UIViewController *destination = [[UIStoryboard storyboardWithName:@"SomeStoryboard" bundle:nil] instantiateInitialViewController];
    
        UIStoryboardSegue *segue = [UIStoryboardSegue segueWithIdentifier:@"identifier" source:self destination:destination performHandler:^(void) {
            //view transition/animation
            [self.navigationController pushViewController:destination animated:YES];
        }];
    
        UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
        [self shouldPerformSegueWithIdentifier:segue.identifier sender:cell];//optional
        [self prepareForSegue:segue sender:cell];
    
        [segue perform];
    }
    

    Note: UITableViewCell *cell is used as sender to keep default TableViewController response behaviour.

    0 讨论(0)
  • 2020-12-13 19:14

    I tried everything I had read but still had no success. I've managed to get it working using Rob Browns Storyboard Link It's easy to implement and works really fast

    0 讨论(0)
  • 2020-12-13 19:18

    Adding a Reference to Another Storyboard - Apple developer doc

    0 讨论(0)
  • 2020-12-13 19:18

    Finally XCode 7 has added this feature in which you can segue between view controllers in two different storyboards using interface builder. Till now, we had to do this programatically.

    0 讨论(0)
提交回复
热议问题