0

我有一個ViewController 3視圖:Rootview顯示工具欄與UISegmentedControl,tableView和calendarView。如何將2個UIView合併到1個視圖控制器中?

我有XIB的rootView和tableView,但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; 
     } 
    } 
} 

回答

0

是否使用兩種不同的初始化的方法適合您的需求?​​或同樣initWithNibName:@"nib2" ?? 否則您需要指定想要實現的更多點

相關問題