【发布时间】:2018-03-19 11:00:07
【问题描述】:
我正在尝试在 Objective C 中构建一个简单的应用程序,利用我的AppDelegate 模块中的属性字典来自定义我的故事布局的各种导航项的外观。
代码构建良好,没有错误,但是当它部署到我的测试设备上时,我得到了一个 SIGABRT。
我正在使用最新版本的 Xcode(9.2);情节提要全部设置为“Builds for iOS 8.2 and later”;部署目标设置为 8.1。
我在代码中使用 UITextAttributeTextShadowColor, nil 没有问题,但自 iOS 7.0 以来已弃用,因此我将其更新为 NSShadowAttributeName, nil,但现在无法使用。
我做错了什么?
具体的 SIGABRT 错误为:Terminating app due to uncaught 异常'NSInvalidArgumentException',原因:'-[UIDeviceRGBColor shadowColor]: 无法识别的选择器发送到实例 0x1d447cf00'。
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *attribs = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:170.0/255.0 green:21.0/255.0 blue:29.0/255.0 alpha:1.0],
NSForegroundColorAttributeName,
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0],
NSShadowAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes: attribs];
[[UIBarButtonItem appearance] setTitleTextAttributes: attribs forState:UIControlStateNormal];
return YES;
}
【问题讨论】:
-
Larme 和 CodeChanger 都帮助我取得了成功。我的问题更为根本。在为 NS 交换 UI 时,语法会发生变化,因此键和参数是相反的,我一定是代码盲,所以我看不到哪个参数正在使用哪个键!我在代码中缺少正确的语法来配对适当的 NSShadow 参数。
标签: objective-c xcode9.2