我用这段代码做的是抓取一个图像序列,抓取它的名字。然后将 View 的标题设置为播放序列的序列名称,然后将标题设置回旧标题。
问题是导航栏上的标题似乎没有改变。 NSLogs 正在输出正确的值。
我记得以前遇到过这个问题并用一些“刷新”方法解决了它。
这是相关的代码。
-(void)playSequence
{
if (([animatorViewController isAnimating] == FALSE) && (btnDisable == FALSE))
{
Sequence *tempSequence;
tempSequence = [fullStepList objectAtIndex:lastPlayedSequence];
self.title = [NSString stringWithFormat:@"Assembly - %@", tempSequence.subName];
NSLog(self.title);
[self startAnimator:tempSequence.imageNameScheme forNumFrames:tempSequence.numberOfFrames playInReverse:FALSE];
tempSequence = nil;
tempSequence = [fullStepList objectAtIndex:queuedSequence];
self.title = [NSString stringWithFormat:@"Assembly - %@", tempSequence.subName];
NSLog(self.title);
tempSequence = nil;
}
}
编辑:这种更改标题的方法在此类中的其他位置起作用。当尝试设置它两次导致问题时,问题似乎出现了。
EDIT2:它实际上是一个接一个地运行两个标题更改......事实上将它设置回以前的状态让我失望。
最佳答案
一个导航项可能包含四个内容:leftBarButtonItem、rightBarButtonItem、title 和 titleView。当您需要更改标题时,您应该将标题分配给 navigationItem 的 title 属性,而不是 View 的 title 属性。所以它看起来像:
self.navigationItem.title = [NSString stringWithFormat:@"Assembly - %@", tempSequence.subName];
self.title 指向未显示在导航栏中的 viewControllers 标题。
关于iphone - iOS - 导航标题未更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7248460/