1.我想在字典里插入一个整数,但是一直失败。NSInteger类型的变量不允许写进字典里,只能用NSString转了放进去
---
Object或Key只能是对象(id或继承自id的)
inti =1;[dic addObject:[NSNumbernumberWithInt:i] forKey:@"somekey"];//或者[dic addObject:@1forKey:@"somekey"];//取出时i = [[dic objectForKey:@"somekey"] intValue];
2
将string字符串转换为array数组
NSArray *array = [Str componentsSeparatedByString:@","];//分隔符逗号
将array数组转换为string字符串
NSString *tempString = [mutableArray componentsJoinedByString:@","];//分隔符逗号
3.在使用NSUserDefaults的时候插入数据有时候会报以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSUserDefaults setObject:forKey:]: attempt to insert non-property list object { array = ( { 481 = { msg = { 1413462307 = "[3197]/U4e8c/U5341/U516b/U56de/U590d/U4e86/U4f60/Uff1a/U4f60/U6211"; }; "new_msg" = 1; "usr_id" = 2; "usr_name" = ""; "usr_tx" = ""; }; } );} for key newMsgArrayDict'
这种错误的原因是插入了不识别的数据类型,NSUserDefaults支持的数据类型有NSString、 NSNumber、NSDate、 NSArray、NSDictionary、BOOL、NSInteger、NSFloat等系统定义的数据类型。
自定义的类型需要转成NSData再存入。
4.有时候服务器返回的数据存在换行,空格,很不雅观
string = [string stringByReplacingOccurrencesOfString: @"\r" withString:@""]
string =[string stringByReplacingOccurrencesOfString: @"\n" withString:@""]
5.有时候输入文本的时候,输入换行,但是\n与@“<\br>”要互相转化
NSString *contentText = [_textView.text stringByReplacingOccurrencesOfString:@"\n" withString:@"
"];
网友评论