iOS注意事项
来源:互联网 发布:杭州淘宝商学院地址 编辑:程序博客网 时间:2024/05/17 08:51
1.封装,继承,多态
Set:方法1.作用提供一个方法给外界设置成员变量的命名规范
作用:提供一个变量方法给外界设置成员变量值,可以在方法里面对参数进行相应的过
set后面跟上成员变量的名称,成员变量的首字母必须大写
一定要接收一个参数,而且参数类型跟成员变量类型一致
形参的名称不能跟成员变量名一样
Get:方法
返回对象内部的成员变量
肯定有返回值,返回值类型肯定和成员变量类型一致,方法名跟成员变量名一致,不需要接 受任何参数
#import <Fountation/Fountation.h>
@interfceStudent : NSObject
{
Int age;
}
-(void)setAge:(int)newAge;
@end
@implementationStudent
-(void)setAge:(int )newAge{
if (newAge<= 0)
{
newAge =1;
}
age =newAge;
}
-(void)study
{
NSLog("%d学生在学习",age);
}
@end
Int main()
{
Student *stu =[Student new];
[stu setAge:0];
[stustudy];
}
2.对于字符一应该用单引号扩起来'Z'
双引号表示一个字符串
3.类方法智能用类进行调用,当类方法用实例调用时,会出现闪退现象导致程序崩溃
4.对象方法不能用类对象调用,也会出现程序崩溃
5.两者的区别,类方法+开头,只能由类对象来调用
对象方法-开头,只能由对象来调用,两者可以重名,对象方法中能调用当前 对象的成员变量
//
// main.m
// yun
//
// Created by qingyun on 15/7/27.
// Copyright (c) 2015年qingyun. All rights reserved.
//
#import<Foundation/Foundation.h>
@interface Score:NSObject
{
int _cscore;
int _ocscore;
int _totalscore;
int _averagescore;
}
-(void)setCscore:(int)cscore;
-(int) cscore;
-(void)setOcscore:(int)ocscore;
-(int)ocscore;
-(int)totalscore;
-(int)averagescore;
@end
@implementation Score
-(void)setCscore:(int)cscore
{
_cscore =cscore;
_totalscore = _ocscore+_cscore;
_averagescore = _totalscore/2;
NSLog(@"_total value is %d\n",_totalscore);
}
-(int)cscore
{
return _cscore;
}
-(void)setOcscore:(int)ocscore
{
_ocscore=ocscore;
}
-(int)ocscore
{
return _ocscore;
}
-(int)totalscore
{
return _totalscore;
}
-(int)averagescore
{
return _averagescore;
}
@end
int main ()
{
Score *s =[Scorenew];
[ssetOcscore:100];
[ssetCscore:90];
[saveragescore];
int a = [s totalscore];
NSLog(@"总分:%d",a);
return 0;
}
- IOS注意事项
- iOS注意事项
- ios注意事项
- ios-注意事项
- IOS注意事项
- ios屏幕旋转注意事项
- iOS UIAlertView使用注意事项
- IOS block编程注意事项
- iOS NSTimer使用注意事项
- IOS切图注意事项
- IOS block编程注意事项
- IOS注意事项(2)
- ios开发---注意事项
- ios socket通讯注意事项
- iOS---touch使用注意事项
- ios本地化以及注意事项
- iOS远程推送注意事项
- IOS发布注意事项
- 通过SpringMVC+Annotation实现方法、按钮级别的细粒度权限控制
- 数据库事务(写得比较到位)
- 《Friends Season 04, Episode 01》---笔记
- 理解lightdm.conf
- TP中cache方法使用
- iOS注意事项
- V4包的经常错误
- Compare And Swap(CAS)实现无锁多生产者
- 精通Hibernate——Hibernate内置标识符详解
- Lintcode 主元素
- 【设计模式】代理模式实现连接池
- 设计模式之工厂模式
- 237 Delete Node in a Linked List
- Matlab--多项式