1.
CGRect tmpRect = [label.text boundingRectWithSize:CGSizeMake(XScreenWidth-30-30, 1000) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:label.font,NSFontAttributeName, nil] context:nil];
高度=tmpRect.size.height
但是有時(shí)候這樣不對(duì),因?yàn)槲以?S上出現(xiàn)顯示未完全的情況。這是因?yàn)楂@取到的應(yīng)該是有余數(shù)缔刹,但是把末尾余數(shù)去掉了。所以可以利用這個(gè)方法來(lái)解決隐砸,就是向上取整匾旭。
ceilf(tmpRect.size.height) 就可以了
參考文章 :boundingRectWithSize計(jì)算文字高度不準(zhǔn)問(wèn)題
2.從二維碼掃描中獲取相關(guān)信息,并判斷獲取到的是否正確
? ? ? ? ? ? str = [str stringByReplacingOccurrencesOfString:@"sn=" withString:@"***"];
? ? ? ? ? ? strTest =@"***";
? ? ? ? ? ? str = [str stringByReplacingOccurrencesOfString:@"&wmac" withString:@"###"];
? ? ? ? ? ? NSRange star = [str rangeOfString:@"***"];//匹配得到的下標(biāo)
? ? ? ? ? ? NSRange end = [str rangeOfString:@"###"];//匹配得到的下標(biāo)
? ? ? ? ? ? NSLog(@"===str==%@",str);
? ? ? ? ? ? if (!([str rangeOfString:strTest].location+14 != NSNotFound)) {//判斷是否為空
? ? ? ? ? ? ? ? str = [str substringWithRange:NSMakeRange(star.location+3,14)];//截取范圍內(nèi)的字符串
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? str = @"";
? ? ? ? ? ? }
3.在NSUserDefaults 存儲(chǔ)可變數(shù)組的問(wèn)題解決
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *_arr = [NSMutableArray arrayWithCapacity:0];
NSMutableArray *mutableCopyArr = [NSMutableArray arrayWithCapacity:0];
mutableCopyArr = [userDefaults objectForKey:@"DeviceSN"];
? _arr = [mutableCopyArr mutableCopy];
讀取到的數(shù)據(jù)必須要用另一個(gè)數(shù)組接收尽棕,不然就會(huì)直接報(bào)錯(cuò)答憔。
這些都是錯(cuò)的~~~如果想要修改保存過(guò)的數(shù)據(jù)味赃,還是用字符串保險(xiǎn),也就是拼接虐拓。
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
strMut = [deviceStr stringByAppendingString:[NSString stringWithFormat:@"%@*",_manager.ScanID]];
[userDefaults removeObjectForKey:@"Device"];
?[[NSUserDefaults standardUserDefaults]synchronize];
?[[NSUserDefaults standardUserDefaults ]setObject:strMut forKey:@"Device"];
?[[NSUserDefaults standardUserDefaults]synchronize];
??NSLog(@"===strmut%@",[userDefaults objectForKey:@"Device"]);
這句打印的話很重要心俗,沒有的話可能存儲(chǔ)不了,在刪了之后
4.uitableview隱藏多余的cell橫線
_tableView.tableFooterView = [[UIView alloc] init];