如何将 2 个 UIView 组合成 1 个视图控制器?
我有一个具有 3 个视图的 ViewController:Rootview,显示带有 UISegmentedControl、tableView 和 calendarView 的工具栏。
我有 rootView 和 tableView 的 XIB,但 calendarView 没有 XIB。
我需要以某种方式组合代码来加载日历视图以适应此 ViewController。之前,我使用calendarView作为它自己的viewController。
calendarView 的代码:
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
calendar = [[TKCalendarMonthView alloc] init];
calendar.delegate = self;
calendar.dataSource = self;
}
return self;
}
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
UIBarButtonItem *actionButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(dismissCalendarView)];
self.navigationItem.leftBarButtonItem = actionButton;
[actionButton release];
int statusBarHeight = 0;
CGRect applicationFrame = (CGRect)[[UIScreen mainScreen] applicationFrame];
self.view = [[[UIView alloc] initWithFrame:CGRectMake(0, statusBarHeight, applicationFrame.size.width, 300.0)] autorelease];
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view.backgroundColor = [UIColor clearColor];
self.title = @"Select Workout";
calendar.frame = CGRectMake(0, 0, calendar.frame.size.width, calendar.frame.size.height);
NSLog(@"%f height", applicationFrame.size.height);
[self.view addSubview:calendar];
[calendar reload];
}
如果我将该代码直接放入这个新的 viewController 中,它不会尊重 UISegmentedControl 并且只会在启动时显示。
这是 UISegmentedConrol 的代码:
- (void)segmentedControl:(SVSegmentedControl*)segmentedControl didSelectIndex:(NSUInteger)index
{
switch (index)
{
case 0:
{
[self.view addSubview: tableView1];
tableView1.hidden = NO;
calendar.hidden = YES;
[calendar removeFromSuperview];
break;
}
case 1:
{
[self.view addSubview: calendar];
tableView1.hidden = YES;
calendar.hidden = NO;
[tableView1 removeFromSuperview];
break;
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用两种不同的 init-Methods 是否满足您的需求?
initWithNibName:@"nib1"
或者同样initWithNibName:@"nib2"
?否则,您将需要详细说明您想要实现的目标
Does using two different init-Methods fit your needs?
initWithNibName:@"nib1"
or likewiseinitWithNibName:@"nib2"
??Otherwise you will need to specify what you want to achieve a little more