【问题标题】:Navigating to another view using the UINavigationController使用 UINavigationController 导航到另一个视图
【发布时间】:2012-03-08 21:40:37
【问题描述】:

我在我的应用程序中使用UINavigationController,由于某种原因,它不允许我将页面切换到名为CompanyView 的third xib。它从第一到第二转换得很好,但不是第二到第三。我可能做错了什么,但如果有人可以查看我的代码,那就太好了。我相信我的按钮设置正确。 这是我的.h file xib 不会改变视图:

#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

【问题讨论】:

    标签: iphone ios5 uinavigationcontroller xcode4.2 uinavigationbar


    【解决方案1】:

    尝试以这种方式初始化您的公司视图。

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

    【讨论】:

    • 嗯...它仍然没有切换。我应该将一些代码添加到我的 CompanyView.h 和 .m 文件中吗?
    【解决方案2】:

    我是这样设置的:

    - (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];
    }
    

    也许对你有帮助

    【讨论】:

    • 对不起,我很笨,但你知道我可以把这段代码放在哪里吗?你有没有把它放在你的 .m 文件中任何特别 John 的地方?
    • 无论您按什么进入下一个视图,您都应该把除- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 之外的所有内容都放在哪里,因为这是在您按下表格行的情况下使用的。您还需要更改 [factoryCategoryNameArray objectAtIndex:indexPath.row] 来解决您的需求。所以 controller.title = @"这里的新标题"; avc 也不会匹配你的,avc 是 activityViewController。因此,无论您的 AVC 是什么,都将其更改为匹配。
    • @Maple 让我把你链接到我用来学习这个的第一个教程。 :] iosdevnotes.com/2011/03/uinavigationcontroller-tutorial
    • 太棒了!感谢您的耐心和帮助约翰!
    猜你喜欢
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-21
    相关资源
    最近更新 更多