I have a ViewController with 3 views: Rootview that shows toolbar with UISegmentedControl, tableView, and calendarView.
I have XIB for the rootView, and tableView, but the calendarView doesn’t have a XIB.
I need to somehow combine the code to load the calendar view to fit with with this ViewController. Before, I was using the calendarView as its own viewController.
The code for 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];
}
If I put that code directly into this new viewController, it does not respect the UISegmentedControl and just shows up at launch.
Here is the code for the 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;
}
}
}
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