很抱歉,如果它被问到某个地方,但作为初学者,我需要一个非常具体的答案来解决我的问题。哪里出错,纠正和建议。
我在应用程序下写了那些didFinishLaunchingWithOption:
UIColor *myBackgroundColor = [[UIColor alloc]initWithRed:.87 green:.77 blue:.56 alpha:.99];
[window setBackgroundColor:myBackgroundColor];
它工作,并改变背景的颜色,然后我尝试将这两个消息分开。
UIColor *myBackgroundColor = [UIColor alloc];
[myBackgroundColor initWithRed:.87 green:.77 blue:.56 alpha:.99]
[window setBackgroundColor:myBackgroundColor];
我应该如何编码以使其正常运行?我需要理由和更正。非常感谢。
答案 0 :(得分:3)
您不能认为alloc
和init
具有相同的返回值。
以下内容应该有效:
UIColor *myBackgroundColor = [UIColor alloc];
myBackgroundColor = [myBackgroundColor initWithRed:.87 green:.77 blue:.56 alpha:.99]
[window setBackgroundColor:myBackgroundColor];
我不明白你为什么要添加额外的行。
答案 1 :(得分:0)
使用...
[UIColor colorWithRed:0.87 green:0.77 blue:0.56 alpha:0.99];