2012-03-08 30 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

相关问题