我有一个使用TabBar模板的应用程序。在其中一个视图控制器中,我想添加一个uinavigationcontroller。我在.h文件中声明它;无法将UINavigationController以编程方式添加到TabBar应用程序
#import <UIKit/UIKit.h>
#import "AnotherViewController.h"
@interface SecondViewController : UIViewController <UINavigationControllerDelegate> {
UIButton *UIButton *gotoAnotherView;;
AnotherViewController *anotherView;
UINavigationController *navigationController;
}
@property(nonatomic,retain) UIButton *UIButton *gotoAnotherView;;
@property(nonatomic,retain) AnotherViewController *anotherView;
@property(nonatomic,retain) UINavigationController *navigationController;
-(void)buttonPressed:(id)sender;
@end
这是我的.m文件
#import "SecondViewController.h"
@implementation SecondViewController
@synthesize navigationController, anotherView, gotoAnotherView;
-(void)buttonPressed:(id)sender {
anotherView = [[AnotherViewController alloc]init];
[navigationController pushViewController:anotherView animated:YES];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
navigationController = [[UINavigationController alloc ]initWithRootViewController:self];
[navigationController.navigationBar setFrame:CGRectMake(0, 0, 320, 44)];
[self.view addSubview:navigationController.navigationBar];
gotoAnotherView = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 40, 40)]; //kategoributonlari
UIImage *image = [UIImage imageNamed:@"1.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(110, 5, 100, 20);
[self.view addSubview:imageView];
[kategori1 setBackgroundImage:image forState:UIControlStateNormal];
[kategori1 addTarget:self
action:@selector(buttonPressed:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:kategori1];
[super viewDidLoad];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
但是我可以从该navigationcontroller深入一层导航栏看到(后面会出现按钮),但主要观点仍与我gotoAnotherView相同按钮。
我想我可能不会让navigationcontroller控制整个视图。我会很感激任何帮助。
谢谢。
为什么性能也声明为成员变量? –