0

我有一个带有 3 个视图的 ViewController:显示带有 UISegmentedControl、tableView 和 calendarView 的工具栏的 Rootview。

我有用于 rootView 和 tableView 的 XIB,但 calendarView 没有 XIB。

我需要以某种方式组合代码以加载日历视图以适应此 ViewController。之前,我使用 calendarView 作为它自己的 viewController。

日历视图的代码:

// 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;
        }
    }
}
4

1 回答 1

0

使用两种不同的初始化方法是否适合您的需求?initWithNibName:@"nib1"还是同样initWithNibName:@"nib2"?否则,您将需要详细说明您想要实现的目标

于 2011-06-25T21:36:55.150 回答