我有一个UITabBarController应用程序,第一个控制器作为导航控制器。 我将UIToolbar子类化了:
CustomToolbar.h
#import <UIKit/UIKit.h>
@interface CustomToolbar : UIToolbar
{
UINavigationController *navigationController;
}
@property (nonatomic, retain) UINavigationController *navigationController;
- (void)pressButton:(id)sender;
@end
CustomToolbar.m
#import "CustomToolbar.h"
#import "AnotherViewController.h"
@implementation CustomToolbar
@synthesize navigationController;
- (void)pressButton:(id)sender
{
AnotherViewController *viewController = [[AnotherViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// add buttons
UIBarButtonItem *mybutton = [[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStyleBordered target:self action:@selector(pressButton:)];
[mybutton setEnabled:YES];
// add buttons to the array
NSArray *items = [NSArray arrayWithObjects:mybutton, nil];
[self setItems:items];
[mybutton release];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
MyViewController.m
[...]
CustomToolbar *myToolbar = [[CustomToolbar alloc] initWithFrame:CGRectMake(0, 436, self.navigationController.view.frame.size.width, 44)];
[self.navigationController.view addSubview:myToolbar];
[self.navigationController.view setFrame:CGRectMake(0, 0, self.navigationController.view.frame.size.width, self.navigationController.view.frame.size.height - myToolbar.frame.size.height)];
[...]
一切正常,我看到工具栏和按钮但它无法点击。这里有什么想法吗?
修改
我发现了问题。这是因为我调整了导航控制器框架的大小。但我需要来调整它的大小。解决方案?