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];
- (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仅局限于字符串的比较