导航控制器显示提示

Bau*_*aub 3 iphone objective-c uinavigationcontroller

如何UINavigationController在按下按钮时显示提示?我已经设置了我的文字[[[self navigationController]navigationItem]setPrompt:[NSString stringWithFormat:@"Prompt is working!"]];

编辑:为了澄清,我有一个按钮调用一个IBAction设置提示如下,但我需要找到一种方法,一旦按下该按钮显示提示:

-(IBAction)test:(id)sender
{
    [[[self navigationController]navigationItem]setPrompt:[NSString stringWithFormat:@"Prompt works!"]];
    //I want it to display right after I set it, so I'm missing something and can't figure it out through the documentation
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试[[[self navigationController]navigationBar]pushNavigationItem:nav animated:YES];但是会引发错误说明Cannot call pushNavigationItem:animated: directly on a UINavigationBar managed by a controller.

Ahm*_*dal 21

您应该像这样设置提示文本:

self.navigationItem.prompt = @"This is the title";
Run Code Online (Sandbox Code Playgroud)

  • UINavigationController从它显示的当前顶视图控制器获取所有导航栏项目信息(按钮,标题视图,提示等).因此,您需要在视图控制器本身上设置它们,而不是在导航控制器上. (2认同)