IOS 7 Study - Manipulating a Navigation Controller’s Array of View

Problem
You would like to directly manipulate the array of view controllers associated with a
specific navigation controller


Solution
Use the viewControllers property of the UINavigationController class to access and
modify the array of view controllers associated with a navigation controller

 

- (void) goBack {
    /* Get the current array of View Controllers */
    NSArray *currentControllers = self.navigationController.viewControllers;

    /* Create a mutable array out of this array */
    NSMutableArray *newControllers = [NSMutableArray
                                      arrayWithArray:currentControllers];

    /* Remove the last object from the array */
    [newControllers removeLastObject];

    /* Assign this array to the Navigation Controller with animation */
    [self.navigationController setViewControllers:newControllers
        animated:YES];
}

 

posted @ 2014-02-20 11:46  Master HaKu  阅读(201)  评论(0编辑  收藏  举报