Context
I'm using the 'initWithNavigationBarClass' method to initialize a UINavigationController with a custom toolbar, here is the line where I alloc init the UINavigationController
navigationController = [[UINavigationController alloc] initWithNavigationBarClass:nil toolbarClass:[QuestionToolbar class]];
Is the class, "QuestionToolbar", I subclass UIToolbar and override drawrect, here is the drawRect method:
- (void)drawRect:(CGRect)rect
{
[super drawRect:rect];
UIImage *backgroundImage = [UIImage imageNamed:@"44px_background_red.png"];
[backgroundImage drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
Here is pertinent code in the viewController where I attempt to add the UIBarButtonItems
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *beginItem = [[UIBarButtonItem alloc] initWithTitle:@"Begin Quiz" style:UIBarButtonItemStylePlain target:self action:@selector(beginAction:)];
[beginItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];
NSArray *items = [NSArray arrayWithObjects:spacer, beginItem, spacer, nil];
[self.navigationController.toolbar setItems:items];
[self.navigationController setToolbarHidden:NO];
Problem
How do I go about adding UIBarButtonItems to this toolbar as they don't show-up when I try to add them?
I assume it's something to do with my overriding drawRect