Tôi có một số UIViewController
được gọi là RootViewController
và A UIViewController
được gọi là NewsViewController
. Tôi muốn hiển thị NewsViewController
bên trong một UIView
(UIView
chỉ là một phần của màn hình) mà tôi đã tạo bên trong RootViewController
. Tôi đang sử dụng kịch bản và ứng dụng của tôi cần hỗ trợ iOS 5 (vì vậy tôi không thể sử dụng segues nhúng aka Container từ IB) mãTải UIViewController bên trong Chế độ xem vùng chứa bằng StoryBoard
RootViewController:
- (void)viewDidLoad
{
[super viewDidLoad];
NewsViewController *news = [[NewsViewController alloc]init];
news.view.frame = self.newsSection.bounds;
[self.newsSection addSubview:news.view];
[self addChildViewController:news];
// Do any additional setup after loading the view.
}
Tôi cũng kết nối cả UIViewControllers với một segue. Bản tin UIView sẽ vẫn trống. Tôi đang làm gì sai?
Edit:
này làm việc cho tôi, đó là cách tiếp cận đúng không?
- (void)viewDidLoad
{
[super viewDidLoad];
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
NewsViewController *news = [storyboard instantiateViewControllerWithIdentifier:@"NewsViewControllerID"];
news.view.frame = self.newsSection.bounds;
[self.newsSection addSubview:news.view];
[self addChildViewController:news];
[news didMoveToParentViewController:self];
}
bạn đã cố gắng của tôi câu trả lời? – stosha
Có. Nó không hoạt động. – Segev