参考博客:https://blog.csdn.net/wu_gq/article/details/102551728
最近在ios16 发布之后,已经发布很久的App突然崩溃,报错如下:
2022-09-19 14:33:38.505774+0800 fmspeed[739:66016] -[__NSCFType _isDynamic]: unrecognized
selector sent to instance 0x282e84f00
2022-09-19 14:33:38.506083+0800 fmspeed[739:66016] *** Terminating app due to uncaught
exception 'NSInvalidArgumentException', reason: '-[__NSCFType _isDynamic]: unrecognized
selector sent to instance 0x282e84f00'
*** First throw call stack:
(0x1bef4a248 0x1b8317a68 0x1bf0be3f0 0x1bef60360 0x1befc8660 0x1c20af620 0x1c115c030
0x1c127a754 0x1c175a4a4 0x1c16f329c 0x1bef53948 0x1befdded0 0x1c12c1c58 0x1c12c1a94
0x1c12c1404 0x1c12bf268 0x1c12bee0c 0x1c1298f14 0x1c1298524 0x1c1297f4c 0x1c1297984
0x102fe63d4 0x102ff51c4 0x1c1402264 0x1030039a4 0x103003a90 0x102fa0a7c 0x102fa0350
0x10308d62c 0x102ef4194 0x1b94128b8 0x1bf00e66c 0x1befcace8 0x1bef6e958 0x1befbc2dc
0x1befc11e4 0x1f7de1368 0x1c1470d88 0x1c14709ec 0x1c79202a0 0x102fde994 0x102fde91c
0x102fdea70 0x1dd2e5948)
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
'-[__NSCFType _isDynamic]: unrecognized selector sent to instance 0x282e84f00'
terminating with uncaught exception of type NSException
根据调用堆栈,经过把代码一点点屏蔽排查发现只要调用setTitleTextAttributes
即可崩溃。最终只能换一种实现思路。具体代码如下:
if #available(iOS 13.0 , *)
{
let appence = UITabBarAppearance();
appence.stackedLayoutAppearance.selected.titleTextAttributes = selectAttr
appence.stackedLayoutAppearance.normal.titleTextAttributes = nortextAttr
tabConbtrol.tabBarItem.standardAppearance = appence
}
else
{
tabConbtrol.tabBarItem.setTitleTextAttributes(nortextAttr, for: UIControl.State.normal)
tabConbtrol.tabBarItem.setTitleTextAttributes(selectAttr, for: UIControl.State.selected)
}