【发布时间】:2011-06-23 23:27:47
【问题描述】:
我有一个视图,它的底部 UIToolBar 中有一个 UISegmentedControl,它有 2 个段。加载时的视图应默认为查看1.然后选择段2时,应切换到查看2等。
现在,当我单击段 2 时,它会隐藏视图 1,然后切换到第二个视图,但是如何保持 segmentedControl 显示?当视图 1 被隐藏时,控件也被隐藏。
我需要总共创建 3 个视图吗?并将视图 1 和 2 作为默认视图的子视图,其中只有分段控件?
编辑:
- (void)segmentedControl:(SVSegmentedControl*)segmentedControl didSelectIndex:(NSUInteger)index
{
LogResultsViewController* v1 = [[LogResultsViewController alloc] initWithNibName: @"LogResultsViewController" bundle:nil];
CalendarController* v2 = [[CalendarController alloc] initWithNibName: @"CalendarController" bundle:nil];
if (index == 0)
{
[self.view addSubview: v1.view];
}
else
{
[self.view addSubview: v2.view];
}
}
这是用于加载此视图的代码:
- (void)loadView
{
UIBarButtonItem *actionButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(dismissCalendarView)];
self.navigationItem.leftBarButtonItem = actionButton;
[actionButton release];
int statusBarHeight = 20;
CGRect applicationFrame = (CGRect)[[UIScreen mainScreen] applicationFrame];
self.view = [[[UIView alloc] initWithFrame:CGRectMake(0, statusBarHeight, applicationFrame.size.width, applicationFrame.size.height)] autorelease];
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.view.backgroundColor = [UIColor grayColor];
calendar.frame = CGRectMake(0, 0, calendar.frame.size.width, calendar.frame.size.height);
[self.view addSubview:calendar];
[calendar reload];
}
【问题讨论】:
标签: iphone objective-c xcode uiview uisegmentedcontrol