【问题标题】:UINavigationController in UIPopoverController: setting the titleUIPopoverController 中的 UINavigationController:设置标题
【发布时间】:2012-08-21 06:11:49
【问题描述】:

我试图在UIPopoverController 中显示UINavigationController,但由于某种原因我无法设置标题。

SearchViewController *searchView = [[[SearchViewController alloc] init] autorelease];

UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:searchView];
[popover presentPopoverFromBarButtonItem:_searchBarButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

我尝试在- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil中更改它

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Change the title
    UILabel *label = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont boldSystemFontOfSize:20.0];
    label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
    label.textAlignment = UITextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    label.text = @"Print / Email";
    [label sizeToFit];
    self.navigationItem.titleView = label;
}
return self;
}

我也尝试在- (void)viewDidLoad中设置它

- (void)viewDidLoad
{
[super viewDidLoad];

self.contentSizeForViewInPopover = CGSizeMake(320.0, 250.0f);

self.navigationItem.title = @"Print / Email";
self.title = @"Print / Email";
}

但在任何情况下标题都不起作用,我还是做错了什么吗?

【问题讨论】:

  • 尝试从 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 中删除 titleview 标签代码。

标签: iphone ios uinavigationcontroller uipopovercontroller


【解决方案1】:

编辑在 UINavigationController 广告中添加您的 SearchViewController 控制器,在 UIPopoverController 中像这样:

SearchViewController *searchView = [[[SearchViewController alloc] init] autorelease];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:searchView];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navController];
[popover presentPopoverFromBarButtonItem:_searchBarButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

现在在 SearchViewController 的 viewDidLoad 方法中:

- (void)viewDidLoad
{
  [super viewDidLoad];
  self.title = @"Print / Email";
}

参考setting-the-title-of-a-uipopovercontroller

【讨论】:

  • 谢谢,但这也不起作用,我之前试过,它仍然是空的。
  • 实际上它只是没有显示,当我这样做时NSLog(@"%@", self.title);它返回正确的标题
  • 您更新的方法确实有效,这似乎是一种奇怪的方法,谢谢!
【解决方案2】:

尝试用这种方式显示弹出框控制器

SearchViewController *searchView = [[[SearchViewController alloc] init] autorelease];
UINavigationController *navCont=[[UINavigationController alloc] initWithRootViewController:searchView];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navCont];
[popover presentPopoverFromBarButtonItem:_searchBarButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

【讨论】:

  • Ny SearchViewController 已经是 UINavigationController,所以应该没什么区别
【解决方案3】:

你可以试试这个:

SearchViewController *searchView = [[[SearchViewController alloc] init] autorelease];

UINavigationController *_nav = [[[UINavigationController alloc] initWithRoot.....:searchView] autorelease];

然后将_nav放入popover。

每个 UIViewController 都有自己的标签栏和导航,但你应该初始化它们。然后你才能正确使用它们。

【讨论】:

    猜你喜欢
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多