I’m diving into iPad development and I’m still learning how everything works together. I understand how to add standard view (i.e. buttons, tableviews, datepicker, etc.) to my UI using both Xcode and Interface Builder, but now I’m trying to add a custom calendar control (TapkuLibrary) to the left window in my UISplitView application which doesn’t involve Interface Builder, right? So if I have a custom view (in this case, the TKCalendarMonthView), how do I programmatically add it to one of the views in my UI (in this case, the RootViewController)? Below are some relevant code snippets from my project…
RootViewController interface
@interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate> {
DetailViewController *detailViewController;
NSFetchedResultsController *fetchedResultsController;
NSManagedObjectContext *managedObjectContext;
}
@property (nonatomic, retain) IBOutlet DetailViewController *detailViewController;
@property (nonatomic, retain) NSFetchedResultsController *fetchedResultsController;
@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext;
- (void)insertNewObject:(id)sender;
TKCalendarMonthView interface
@class TKMonthGridView,TKCalendarDayView;
@protocol TKCalendarMonthViewDelegate, TKCalendarMonthViewDataSource;
@interface TKCalendarMonthView : UIView {
id <TKCalendarMonthViewDelegate> delegate;
id <TKCalendarMonthViewDataSource> dataSource;
NSDate *currentMonth;
NSDate *selectedMonth;
NSMutableArray *deck;
UIButton *left;
NSString *monthYear;
UIButton *right;
UIImageView *shadow;
UIScrollView *scrollView;
}
@property (readonly,nonatomic) NSString *monthYear;
@property (readonly,nonatomic) NSDate *monthDate;
@property (assign,nonatomic) id <TKCalendarMonthViewDataSource> dataSource;
@property (assign,nonatomic) id <TKCalendarMonthViewDelegate> delegate;
- (id) init;
- (void) reload;
- (void) selectDate:(NSDate *)date;
Thanks in advance for all your help! I still have a ton to learn, so I apologize if the question is absurd in any way. I’m going to continue researching this question right now!
Assuming you have initialized the custom
UIView, you need to add it as a subview of theviewController‘s view.– (void)addSubview:(UIView *)view
So an example would be if you have a plain
viewControllercalledmyVC, which has simply a blank whiteUIViewas its view, you would say this:Then it will show up in the
viewController‘s view, taking up the space indicated by theCGRect.The
CGRect‘s coordinates specify a location in the local coordinate system of the superview you are adding to, if I’m not mistaken.CGRect CGRectMake (CGFloat x, CGFloat y, CGFloat width, CGFloat height);