iOS常用知识点总结

1.点击空白回收键盘 - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {

UITouch*touch = [touchesanyObject];
UIView*view = [touchview]; //获取被点击的view
if([viewisKindOfClass:[ActApplyNoSetViewclass]]) {
[self.view endEditing:YES];

}
}
2.打赏时输入金额正则表达式 -(BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string{
NSString*toString = [textField.textstringByReplacingCharactersInRange:rangewithString:string];
if(toString.length>0) {
NSString*stringRegex =@"(\\+|\\-)?(([0]|(0[.]\\d{0,2}))|([1-9]\\d{0,2}(([.]\\d{0,2})?)))?";
NSPredicate*phoneTest = [NSPredicatepredicateWithFormat:@"SELF MATCHES %@", stringRegex];
BOOLflag = [phoneTestevaluateWithObject:toString];
if(!flag) {
returnNO;
}
}
returnYES;
}
3.项目QQ联系我们点击 打开QQ 添加好友或群 NSString *urlStr = [NSString stringWithFormat:@"mqqapi://card/show_pslcard?src_type=internal&version=1&uin=%@&key=%@&card_type=group&source=external", @"483438261",@"ff8c5866c16b3f4b80ed7606d6aecab8fd8242010e25d013b623d3e364461b96"];

NSURL *url = [NSURL URLWithString:urlStr];
if([[UIApplication sharedApplication] canOpenURL:url]){
[[UIApplication sharedApplication] openURL:url];
4.navibar字体颜色
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor],NSForegroundColorAttributeName,nil]];

5.ViewController 向后返回到指定VC for(UIViewController*controllerinself.navigationController.viewControllers) {

if([controllerisKindOfClass:[UserTouPiaoControlVCclass]]) {
[self.navigationControllerpopToViewController:controlleranimated:YES];
}
6.获取webView的高度 _webHeight= [[webViewstringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"]floatValue];

7.duplicate symbols for architecture x86_64错误 错误原因一般是重复倒入相同的类
8.cocoapods 安装命令 pod install --verbose --no-repo-update
9.回收键盘 [self.view endEditing:YES];
10.判断图片格式 - (NSString*)typeForImageData:(NSData*)data {

uint8_tc;
[datagetBytes:&clength:1];
switch(c) {
case0xFF:
return@"image/jpeg";
case0x89:
return@"image/png";
case0x47:
return@"image/gif";
case0x49:
case0x4D:
return@"image/tiff";
}
returnnil;
}
十一、设置父视图的透明度不影响子视图
aView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];

十二、tableView滑倒最顶部
[_tableView setContentOffset:CGPointMake(0,0) animated:NO];



【iOS常用知识点总结】持续更新中~

    推荐阅读