objective-c学习笔记(参考)


1.数组的排序

1
2
3
4
5
6
7
8
-( void ) sort
{
     //[book sortUsingSelector:@selector(compareNames:)];
     [book sortUsingComparator:
      ^(id obj1, id obj2){
          return  [[obj1 email] compare: [obj2 email]];
      }];
}


2.使用copy协议的时候,需要在代码实现类中,为新方法添加下列定义

1
2
3
4
5
6
-(id) copyWithZone: (NSZone *) zone
{
     Fraction *newFract = [[Fraction allocWithZone: zone] init]; //Fraction是类名
     //[newFract setTo: number1 over: number2];  这里可以写一些copy的时候需要执行的语句,也可以不写
     return  newFract;
}


3.NSString与int和float的相互转换

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
NSString *tempA = @ "123" ;
NSString *tempB = @ "456" ;
       
//1,字符串拼接
  NSString *newString = [NSString stringWithFormat:@ "%@%@" ,tempA,tempB];
       
//2,字符转int
int  intString = [newString intValue];
       
//3,int转字符
NSString *stringInt = [NSString stringWithFormat:@ "%d" ,intString];
       
//4,字符转float
  float  floatString = [newString floatValue];
       
//5,float转字符
NSString *stringFloat = [NSString stringWithFormat:@ "%f" ,intString];


4.C中的char类型指针变量比较,需要用strncmp

1
2
3
4
5
6
7
8
9
/**
函数名: strncmp
功 能: 串比较
用 法: int strncmp(char *str1, char *str2, int maxlen);
说明:此函数功能即比较字符串str1和str2的前maxlen个字符。如果前maxlen字节完全相等,返回值就=0;在前maxlen字节比较过程中,如果出现str1[n]与str2[n]不等,则返回(str1[n]-str2[n])。
*/
if  (!strncmp(fuhao,  "c" 1 )) {
     NSLog(@ "dd" );
}


5.分段按钮键值的获取方法

1
2
3
//colorIndex为视图中分段的实例名
int  colorNum;
colorNum = colorIndex.selectedSegmentIndex;


6.分段按钮标题的获取方法

1
2
NSString *navStr;
navStr = [numNav titleForSegmentAtIndex: numNav.selectedSegmentIndex];


7.加载远程web页面

1
2
3
4
//webView为视图中,UIView的实例名
NSURL *appUrl;
appUrl = [[NSURL alloc] initWithString:@ "http://wap.3g.cn" ];
[webView loadRequest:[NSURLRequest requestWithURL:appUrl]];
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值