How to visually create and use static cells in a UITableView embedded in a UIViewController

后端 未结 6 988
深忆病人
深忆病人 2020-11-30 18:34

I\'m using XCode 4.2 and have built my UI using Storyboards. I need to create a view that has content above and below a UITableView and I can achieve this by using a UIViewC

6条回答
  •  温柔的废话
    2020-11-30 18:43

    pmd's answer works but in the event that backward compatibility with iOS 5 is required as well, you can do the embedding programatically using the View Containment API.

    In the viewDidLoad method of your parent UIViewController:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
        MyTableViewController* vc =[storyboard instantiateViewControllerWithIdentifier:@"MyTableVC"];
        [self addChildViewController:vc];
        [self.view addSubview:vc.view];
    
        // ensure embedded view is aligned to top
        CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
        vc.view.frame = frame;
    
        [vc didMoveToParentViewController:self]; 
    }
    

    Don't forget to specify a storyboard ID for your UITableViewController with the static cells.

提交回复
热议问题