我试图分离alloc和initWithRed ...消息,但似乎不起作用 [英] I tried to separate alloc and initWithRed... messages, but it doesn't seems to work

查看:44
本文介绍了我试图分离alloc和initWithRed ...消息,但似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉,如果有人问这个问题,但是作为一个初学者,我需要一个非常具体的答案.哪里有错,请多多指教.

Sorry if it is asked somewhere, but as a beginner, I need a very specific answer for my question. Where is wrong, correction and suggestions.

我在应用程序didFinishLaunchingWithOption下编写了这些代码:

I write those under application didFinishLaunchingWithOption:

UIColor *myBackgroundColor = [[UIColor alloc]initWithRed:.87 green:.77 blue:.56 alpha:.99];
[window setBackgroundColor:myBackgroundColor];

它起作用了,并且改变了背景的颜色,然后我尝试将这两个消息分开.

It worked, and change the color of the background, and then I try to separate those two messages.

UIColor *myBackgroundColor = [UIColor alloc];
[myBackgroundColor initWithRed:.87 green:.77 blue:.56 alpha:.99]
[window setBackgroundColor:myBackgroundColor];

我应该如何编码才能使其正确运行?我将需要理由和更正.非常感谢.

How should I code to make it run correctly? I will need both reason and corrections. Thanks a lot.

推荐答案

您不能假定 alloc init 具有相同的返回值.

You can't assume that alloc and init has the same return value.

以下应能工作:

UIColor *myBackgroundColor = [UIColor alloc];
myBackgroundColor = [myBackgroundColor initWithRed:.87 green:.77 blue:.56 alpha:.99]
[window setBackgroundColor:myBackgroundColor];

我不明白为什么您要添加额外的行.

I don't understand why you'd want to add the extra line though.

这篇关于我试图分离alloc和initWithRed ...消息,但似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆