【问题标题】:Navigation title is not changing in iOS 7iOS 7 中的导航标题没有改变
【发布时间】:2013-09-28 07:32:49
【问题描述】:

我之前在我的应用程序中完成了以下代码。它适用于除 iOS7 之外的所有 iOS。我正在更改 didSelectRow 方法中的导航标题,但它没有更改我在 iOS 7 中的导航栏标题。我在运行时在 didselectrow 中创建了一个新控制器,并在此行中给它一个标题nextController.title = [dataDict objectForKey: kNestedDataKey_title];

- (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {

    NSLogDebug();
    NSDictionary *dataDict = [self.data objectAtIndex: indexPath.row];
    NSString *classNSString = [dataDict objectForKey: kNestedDataKey_class];

    UIViewController *nextController = NULL;
        nextController = [[NestedTableViewController alloc] initWithNibName: nil bundle: nil];
        [self.navigationController pushViewController: nextController animated: YES];
        ((NestedTableViewController *) nextController).data = [dataDict objectForKey: kNestedDataKey_data];


    nextController.title = [dataDict objectForKey: kNestedDataKey_title];
    [nextController release];
}

注意:它在除 iOS 7 之外的所有 iOS 中都可以正常工作

【问题讨论】:

  • 我在这里得到了同样的结果。我用 nib 初始化一个 detailViewController,进行推送,然后将所选项目中的字符串传递给 detailViewController 的标签。标签没有更新..有什么解决办法吗??
  • 你在你的 init 方法中改变它?在 init 方法中传递它,然后将它分配给其他一些 NSString,然后在 viewDidLoad 方法中设置标题。
  • 不,我在 didSelectRowAtIndexPath 中初始化了一个新的 detailViewController。这个新的 detailViewController 有一个 IBOutlet,一个标签。推送后我分配标签文本,但它没有改变(在 iOS 7 中不起作用,这在所有以前的 iOS 中都有效。是模板代码)
  • @Frade if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) { titleiOS7 = [dataDict objectForKey: kNestedDataKey_title]; [NSTimer scheduleTimerWithTimeInterval:0.5 target:self 选择器:@selector(change) userInfo:nil repeats:NO]; } -(void)change{ nextController.title = titleiOS7; }
  • 谢谢马什哈迪!我提出了一个与此问题相关的问题。 Check it here。检查正确答案上的 cmets。

标签: iphone uinavigationbar title ios7


【解决方案1】:

我注意到 iOS 7 中有一个奇怪的行为,即视图加载到内存中有点晚。因此,当您设置标题时,可能尚未创建标题标签。所以在设置瓷砖之前使用这个语句。这将确保您的视图已创建并在内存中。 [下一个控制器视图]; 在这个设定的标题之后 nextController.title = @"标题"; 祝你好运

【讨论】:

  • 你找到了根本原因。 [下一个控制器视图];对我不起作用,但问题是 iOS7 加载有点晚,所以我只是在 1.0 秒内为它添加了一个 NSTimer 并且它起作用了。 [NSTimer scheduleTimerWithTimeInterval:1.0 target:self 选择器:@selector(change) userInfo:nil repeats:NO];
  • 太好了,恭喜。
【解决方案2】:

试试这个代码

 - (void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
    NSLogDebug();
    NSDictionary *dataDict = [self.data objectAtIndex: indexPath.row];
    NSString *classNSString = [dataDict objectForKey: kNestedDataKey_class];

   NestedTableViewController *nextController = NULL;
    nextController = [[NestedTableViewController alloc] initWithNibName: nil bundle: nil];

    nextController.data = [dataDict objectForKey: kNestedDataKey_data];


     nextController.title = [dataDict objectForKey: kNestedDataKey_title];
    [self.navigationController pushViewController: nextController animated: YES];
    [nextController release];
}

【讨论】:

  • nextController 没有数据,也没有可见文件 .xib 或 .m 或 .h,它是在运行时在此处创建的。或者可能是我没有得到你
猜你喜欢
  • 1970-01-01
  • 2015-12-10
  • 1970-01-01
  • 2018-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多