1

我正在尝试在 a 中显示 a UINavigationControllerUIPopoverController但由于某种原因我无法设置标题。

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";
}

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

4

3 回答 3

6

编辑在 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

于 2012-08-21T06:18:12.477 回答
1

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

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];
于 2012-08-21T06:37:07.710 回答
1

你可以试试这个:

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

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

然后将 _nav 放入弹出框。

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

于 2012-08-21T06:42:24.483 回答