简体   繁体   中英

How To Load TableView Into 2nd UIView?

I have a tableview1 that has an add button in navbar. When you press the add button, a new uiview animates in. Currently the new view is blank.

I want to have a table view with sub-table in this new view. It will animate out when the done button is pressed.

My question is, where do I put the code for this 2nd view table and sub table, do I make a new class or keep it with the original class?

Think of what I'm trying to do like adding favorites. I have a favorites list with an add button, I want to click the add button and bring up a table which may have a sub-table from which I can select a cell and it will dismiss this table and add the cell to the initial favorites table.

You will generally have a new class for each type of view controller in use in your app. Once you have your view controllers defined, you typically display them either by pushing onto a navigation controller or by presenting modally.

Example in FavoritesViewController.m when the add button action is invoked:

- (IBAction)addMoreFavorites
{
    AddFavoritesViewController *addFavesVC = [[[FavoritesViewController alloc] init] autorelease];

    // if using a navigation controller
    [self.navigationController pushViewController:addFavesVC];

    // if presenting modally
    [self presentModalViewController:addFavesVC];
}

To dismiss addFavesVC when done you either use [self.navigationController popViewControllerAnimated:YES] or [self dismissModalViewController]

There are many ways to implement adding new favorites to your data model and updating the UI in one or more view controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM