iphone开发零碎知识汇总《二》

1。解析json时报类似

-JSONValue failed. Error is: Unescaped control char 0x0A

这种错误,是因为该json字符串中有隐形字符,例如换行\r,回车\n等字符,导致json无法识别,一种做法是更改服务器代码,使返回的json正规格式,还有一种做法是将得到的json字符串中可能出现的隐形字符过滤掉,具体过滤方法是:

responseStr=[responseStr stringByReplacingOccurrencesOfString:@"\n" withString:@""];

用@""替换掉,值得注意的是,字符串中@"\n"就是转义回车字符。


2.UITableView设置默认选中行

NSIndexPath *ip=[NSIndexPath indexPathForRow:0 inSection:0]; [myTableView selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionTop];

3.UIAlertView中的button点击处理方法:和UIActionSheet类似

声明:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"do something1" @"do something 2", nil]; [alertView setTag:100]; [alertView show]; [alertView release];


在相对应的delegate函数中处理:


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if(alertView.tag==100){ if (buttonIndex == 0) { NSLog(@"修改"); //再弹出一个alertView里面带textField [self popGengGaiAlertView]; } else if(buttonIndex==1) { NSLog(@"button2"); //进行删除 文件夹操作 UIAlertView *tiSiAlert=[[UIAlertView alloc] initWithTitle:@"提示" message:@"确定要删除该类别以及该类别下的所有数据吗?" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil]; tiSiAlert.tag=110; [tiSiAlert show]; [tiSiAlert release]; }else{ NSLog(@"cancell"); } // ... } if(alertView.cancelButtonIndex==buttonIndex){}//处理取消按钮(cancelButtonTitle) } }

csdn这个编辑器好烂啊!!!编辑模式下代码显示一切正常,一发表就显示这么多css代码,就这么写吧,明白人一看就看懂的


4.NSString 的isEqual和 isEqualToString两个方法区别:

isEqual:是string和id类型的值比较,先判断是否为字符串,再判断是否相等

isEqualToString则是直接用于字符串比较,省去判断后者是否为字符串

当前者类型为NSDate等非NSString类型时,前者用处多一些,isEqualToString仅局限于字符串的比较


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值