gpt4 book ai didi

ios - dispatch_async 在重新使用时崩溃应用程序

转载 作者:行者123 更新时间:2023-11-28 21:01:50 27 4
gpt4 key购买 nike

我正在使用 here 的解决方案使 titleView clipsToBounds 始终为真。

我的 ViewController 中有这个并且运行良好,但是,如果我通过按后退按钮离开 ViewController 然后返回,它的应用程序会在 dispatch_async 行崩溃。

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {

if([object isEqual:[[self.navigationController.navigationBar subviews] objectAtIndex:2]]) {

dispatch_async(dispatch_get_main_queue(), ^{

[[self.navigationController.navigationBar subviews] objectAtIndex:2].clipsToBounds = NO;
[self.navigationItem.titleView layoutIfNeeded];
});
}
}

编辑:

我得到的唯一错误是:Thread 1: EXC_BAD_ACCESS (code=1, address=0x102d8860)

除了(lldb)

,控制台不提供任何信息

最佳答案

如果你从viewController出去,你必须移除Observer。

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];

[self.navigationController.navigationBar.subviews[2]
removeObserver:self
forKeyPath:@"clipsToBounds"];
}

关于ios - dispatch_async 在重新使用时崩溃应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48177200/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com