Objective-C语法之创建类和对象
| [日期:2012-07-03] |
来源:Linux社区
作者:totogo2010 |
[字体:大 中 小]
|
2、类方法使用多个参数
2.1添加一个多参数的方法和实现
- ....
- -(void) setNameAndAge:(NSString*) name setAge:(NSInteger) age;
- ....
- ....
- -(void) setNameAndAge:(NSString*) name setAge:(NSInteger) age
- {
- studentName = name;
- studentAge = age;
- }
- ....
2.2调用
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- Student *student = [[Student alloc]init];
- [student setNameAndAge:@"李四" setAge:20];
- [student printInfo];
- [student release];
- [pool release];
- }
打印结果:

评论声明
- 尊重网上道德,遵守中华人民共和国的各项有关法律法规
- 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
- 本站管理人员有权保留或删除其管辖留言中的任意内容
- 本站有权在网站内转载或引用您的评论
- 参与本评论即表明您已经阅读并接受上述条款
|
|
|
|