0
我在xcode 4.2中創建了一個基於視圖的項目,我想實現多級導航以導航到不同的視圖。我的第一個視圖類是ViewController,我顯示一個表。在點擊一行時,我會去下一個有tabbar的班級。在這個我有3個選項卡。第一個選項卡使用的是BuyerViewController類。它有4個按鈕。問題是,當我點擊按鈕時,它不會推下一個課程。iphone中的多級導航xcode 4.2
ViewController.m
- (void)viewDidLoad
{
[email protected]"Select County";
tView = [[UITableView alloc] init]; //tView is my table view object.
tView.frame=CGRectMake(0, 20, 320, 460);
[tView setDelegate:self];
[tView setDataSource:self];
[self.view addSubview:tView];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [countyArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [countyArray objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//This works fine and pushes to my next class to show the tabs.
ShowOptionInTab *showTabbar = [[ShowOptionInTab alloc] initWithNibName:@"ShowOptionInTab" bundle:nil];
[self.navigationController pushViewController:showTabbar animated:YES];
[showTabbar release];
}
ShowOptionInTab.m
-(void)loadView {
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor whiteColor];
self.view = contentView;
[contentView release];
BuyerViewController *buyerController = [[BuyerViewController alloc] init ];
SellerViewController *sellerController = [[SellerViewController alloc] init];
LenderViewController *lenderController = [[LenderViewController alloc] init];
[email protected]"Buyer";
sellerController.title = @"Seller";
lenderController.title = @"Lender";
UITabBarController *tabbarController = [[UITabBarController alloc] init];
tabbarController.view.frame = CGRectMake(0, 0, 320, 460);
[tabbarController setViewControllers:[NSArray arrayWithObjects:buyerController, sellerController,lenderController, nil]];
[buyerController release];
[sellerController release];
[lenderController release];
[self.view addSubview:tabbarController.view];
}
BuyerViewController.m
-(void)viewWillAppear:(BOOL)animated
{
UIButton *quickEstimateButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[quickEstimateButton addTarget:self action:@selector(getTagOfPressedButton:) forControlEvents:UIControlEventTouchUpInside];
[quickEstimateButton setTitle:@"QUICK ESTIMATE" forState:UIControlStateNormal];
quickEstimateButton.tag=1;
quickEstimateButton.frame = CGRectMake(10, 50, 150, 40.0);
[self.view addSubview:quickEstimateButton];
//more 3 buttons are added in same way
}
-(void) getTagOfPressedButton:(id)sender {
UIButton *getTagOfButton = (UIButton *)sender;
int buttonPressedTag = getTagOfButton.tag;
NSLog(@"TAG==========%d",buttonPressedTag);
if(buttonPressedTag==1)
{
NSLog(@"quick estimate pressed");
QuickEstimateViewController *q = [[QuickEstimateViewController alloc] init];
NSLog(@"nav====%@",self.navigationController); //This returns null.
[self.navigationController pushViewController:q animated:YES];
}
}
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
ViewController *overviewViewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:overviewViewController];
navigation.navigationBar.tintColor = [UIColor blackColor];
[overviewViewController release];
[self.window addSubview:[navigation view]];
[self.window makeKeyAndVisible];
}
爲什麼QuickEstimateViewController不顯示?