2012-03-08 106 views
-1

我在我的應用中使用UINavigationController,出於某種原因,它不允許我將頁面切換到名爲CompanyView的third xib。它從第一到第二,但不是第二個第三。我可能做錯了,但如果有人可以查看我的代碼,那將是很棒的。我相信按鈕設置正確。 這裏是我.h filexib不會改變的觀點:使用UINavigationController導航到另一個視圖

#import <UIKit/UIKit.h> 
#import "CompanyView.h" 

@interface MenuView : UIViewController 

-(IBAction)btnClicked:(id)sender; 

@end 

這裏是我的.m file代碼:

#import "MenuView.h" 

@implementation MenuView 

-(IBAction)btnClicked:(id)sender { 

    CompanyView * companyView = [[CompanyView alloc] init]; 

    companyView.title = @"Company"; 

    [self.navigationController pushViewController:companyView animated:YES]; 

    [companyView release]; 
} 



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (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. 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
    // e.g. self.myOutlet = nil; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:  
(UIInterfaceOrientation)interfaceOrientation 
{ 
    // Return YES for supported orientations 
    return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

@end 

回答

0

嘗試初始化您的公司查看這個樣子。

CompanyView *companyView = [[CompanyView alloc] initWithNibName:@"CompanyView" bundle:nil]; 
+0

嗯...它仍然沒有切換。是否有一段代碼應該添加到我的CompanyView.h和.m文件中? – Maple 2012-03-08 21:54:32

0

這是我如何設置它:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
     CategoryPresetViewController *controller = [[CategoryPresetViewController alloc] initWithPVCDelegate:avc]; 
     controller.title = [[factoryCategoryNameArray objectAtIndex:indexPath.row] retain]; 
     if (controller != nil){ 
      [self.navigationController pushViewController:controller animated:YES]; 

     [controller release]; 
} 

也許它可以幫助你

+0

對不起,這是愚蠢的,但你知道我可以放置這些代碼嗎?你把它放在任何特殊約翰的.m文件中嗎? – Maple 2012-03-08 22:00:51

+0

什麼你按下去下一個視圖是你應該把所有東西都放在' - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {'因爲如果你按下了一個錶行。您還需要更改'[factoryCategoryNameArray objectAtIndex:indexPath.row]'來解決您的需求。所以controller.title = @「新標題在這裏」;也avc不會匹配你的,avc是activityViewController。所以無論你的AVC是否改變它匹配。 – 2012-03-08 22:05:51

+0

@Maple讓我把你鏈接到我用來學習的第一個教程。 :] http://www.iosdevnotes.com/2011/03/uinavigationcontroller-tutorial/ – 2012-03-08 22:09:27

相關問題