iOS - 导航标题未更新
我用这段代码所做的就是抓取一个图像序列,抓取它的名称。然后将视图的标题设置为播放序列的序列名称,然后将标题设置回旧标题。
问题是导航栏上的标题似乎没有改变。 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;
}
}
编辑:这种更改标题的方法在此类中的其他位置有效。当尝试设置两次导致问题时,问题似乎就出现了。
编辑2:它实际上正在一个接一个地运行两个标题更改...事实上,它将其设置回之前的状态让我感到失望。
What I'm doing with this bit of code is grabbing an image sequence, grabbing it's name. Then setting the view's title as the sequences name playing the sequence then setting the title back to the old title.
Problem is the title doesn't seem to be changing on the navigation bar. The NSLogs are outputting the correct values though.
I remember having this issue before and solving it with some "refresh" method.
Here is the pertinent code.
-(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;
}
}
EDIT: This method of changing the title is working else where in this class. The problem seems to come in when trying to set it twice that is causing the issue.
EDIT2: It's actually running both title changes one after another... Fact that it was setting it back to previous was throwing me off.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您将 UINavigationController 托管在另一个视图中,则需要执行以下操作:
而不是
否则,您只是更改托管视图导航器的视图的标题。只是一个猜测。
If you are hosting the UINavigationController inside another view, you need to do this:
instead of
Otherwise you are just changing the title of the view hosting the view navigator. Just a guess.
我最近发现自己处于类似的情况。我的视图的标题由带有 NSMutableAttributedString 的标签组成。每当我更新标题时,调用
[self reloadInputViews]
对我来说很有效。I recently found myself in a similar situation. My view's title was comprised of a label with an NSMutableAttributedString. Calling
[self reloadInputViews]
whenever I updated my title worked for me.可怕的 PEBKAC 错误是造成这种混乱的原因。它实际上正在一个接一个地运行两个标题更改......事实上,它将其设置回以前的状态让我感到失望。
The dreaded P.E.B.K.A.C. error was the cause of this confusion. It's actually running both title changes one after another... Fact that it was setting it back to previous was throwing me off.
导航项可能包含四个内容:leftBarButtonItem、rightBarButtonItem、title 和 titleView。当您需要更改标题时,您应该将标题分配给 navigationItem 的 title 属性,而不是视图的 title 属性。所以它看起来像:
self.title 指向你的 viewControllers 标题,它不会显示在导航栏中。
A navigation item may contains four things: leftBarButtonItem, rightBarButtonItem, title, and titleView. When you need to change the title you should assign your title to navigationItem's title property, not to your view's title property. So it would look like:
self.title points to your viewControllers title which don't shows up in the navigationBar.
直到主运行循环执行后,标题才会出现更新。除非 -startAnimator:forNumFrames: 在返回之前调用主运行循环来执行,否则您将看不到更改。
The title won't appear to update until after the main run loop executes. Unless
-startAnimator:forNumFrames:
invokes the main run loop to execute before it returns, you won't see the change.