[英]How do I display different view controllers in a uiview depending on selection through a tableview (Please see the image in description)?
I want to create an ios app, using objectiveC, which has a products list view. 我想使用ObjectiveC创建一个具有产品列表视图的ios应用。 I am looking to create a filter screen for this list, which has a tableview and another view which displays different custom viewcontrollers depending on the row selected in the first tableview. 我正在为此列表创建一个筛选器屏幕,该筛选器屏幕具有一个表视图和另一个视图,该视图根据在第一个表视图中选择的行显示不同的自定义视图控制器。 I am uploading a screenshot of a similar screen from a popular ecommerce app. 我正在从流行的电子商务应用程序上传类似屏幕的屏幕截图。
Can you please help me on how to handle the part where I will have to display different viewcontrollers in the uiview. 您能帮我处理如何在uiview中显示不同的ViewController的部分吗? Thanks in advance! 提前致谢!
Use scrollView for this it is easy to achieve your requirements:) 为此,使用scrollView可以轻松实现您的要求:)
scrollView =[[UIScrollView alloc]init];
scrollView.frame =CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height - 60);
scrollView.pagingEnabled=YES;
scrollView.delegate=self;
scrollView.bounces=NO;
scrollView.showsHorizontalScrollIndicator = YES;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop=NO;
scrollView.indicatorStyle=UIScrollViewIndicatorStyleWhite;
[self.view addSubview:scrollView];
scrollView.contentSize=CGSizeMake(2*scrollView.frame.size.width, scrollView.frame.size.height - 60);
collectionantZ *homeScreen =[self.storyboard instantiateViewControllerWithIdentifier:@"yyy"];
Antzclubtableview *antzClub =[self.storyboard instantiateViewControllerWithIdentifier:@"xxx"];
tableView1.view.frame=CGRectMake(0,19,scrollView.frame.size.width, scrollView.frame.size.height);
tableView2.view.frame=CGRectMake(scrollView.frame.size.width,19,scrollView.frame.size.width, scrollView.frame.size.height);
[scrollView addSubview:tableView1.view];
[scrollView addSubview:tableView2.view];
[self addChildViewController:tableView1];
[self addChildViewController:tableView2];
- (IBAction)tableView1:(id)sender {
[scrollView setContentOffset:CGPointMake(0,0.) animated:YES];
}
- (IBAction)tableView2:(id)sender {
[scrollView setContentOffset:CGPointMake(1 *scrollView.frame.size.width,0.) animated:YES];
}
if you have multiple view controller just adjust this code as per your need 如果您有多个视图控制器,只需根据需要调整此代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.