iOS - 导航标题未更新

发布于 2024-12-02 07:28:24 字数 939 浏览 0 评论 0原文

我用这段代码所做的就是抓取一个图像序列,抓取它的名称。然后将视图的标题设置为播放序列的序列名称,然后将标题设置回旧标题。

问题是导航栏上的标题似乎没有改变。 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

烟织青萝梦 2024-12-09 07:28:25

如果您将 UINavigationController 托管在另一个视图中,则需要执行以下操作:

self.yourNavigationController.title = @"title";

而不是

self.title = @"blah"

否则,您只是更改托管视图导航器的视图的标题。只是一个猜测。

If you are hosting the UINavigationController inside another view, you need to do this:

self.yourNavigationController.title = @"title";

instead of

self.title = @"blah"

Otherwise you are just changing the title of the view hosting the view navigator. Just a guess.

独自唱情﹋歌 2024-12-09 07:28:25

我最近发现自己处于类似的情况。我的视图的标题由带有 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.

凉风有信 2024-12-09 07:28:25

可怕的 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.

不知所踪 2024-12-09 07:28:24

导航项可能包含四个内容:leftBarButtonItem、rightBarButtonItem、title 和 titleView。当您需要更改标题时,您应该将标题分配给 navigationItem 的 title 属性,而不是视图的 title 属性。所以它看起来像:

self.navigationItem.title = [NSString stringWithFormat:@"Assembly - %@", tempSequence.subName];

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.navigationItem.title = [NSString stringWithFormat:@"Assembly - %@", tempSequence.subName];

self.title points to your viewControllers title which don't shows up in the navigationBar.

海夕 2024-12-09 07:28:24

直到主运行循环执行后,标题才会出现更新。除非 -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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文