Object-C和C语言最大的区别也是最大的扩展-----消息(即如何调用一个对象中的函数)
一个简单的消息调用是这样的:
[receiver message];
这是在下一章中会遇到的实例:
[window makeKeyAndVisible];
这条消息给window对象发送makeKeyAndVisible命令.
1.带有参数的消息.
[receiver message:argument];
下面是另一个实例:
[textView setText:@"There are the times …"];
发送多个参数时
[receiver message:arg1 label2:arg2 label3:arg3]
实例:
[myButton setTitle:@"Goodbye" forState:UIControlStateNormal];
2.嵌套消息
对象的创建以这种方式代替接受者
[[UITextView alloc] initWithFrame : textFieldFrame];
将一种颜色作为参数进行传递时,几乎总是这样嵌套一个对UIColor类对象的调用:
[textView setTextColor:[UIColor colorWithWhite:newColor alpha:1.0]];
3.消息接受方
[class message]
例如:
UIButton *myButton =
[UIButton buttonWithType:UIButtonTypeRoundedRect];
在一个类的源代码内部,通常使用self调用函数:
[self setText:@"That try mens' souls. "];
在子类执行自身行为之前先调用此类的父类.
[super initWithFrame:frame]