#pragma mark -- 從新系統方法(目的是爲了解決凸起的button沒有點擊事件) -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { //判斷self.isHidden == NO(關鍵判斷)若是不判斷,push到其餘頁,點擊這個位置也會觸發事件; //self.isHidden == NO 說明當前頁有tabbar,在判斷手指點擊的位置是否發生在按鈕身上,若是是的話就讓按鈕本身去處理事件,不是的話就讓系統去處理事件就能夠了. if (self.isHidden == NO) { //將當前的tabbar的觸摸點轉換座標系,轉換到自定義按鈕身上,生成一個新的點 CGPoint newP = [self convertPoint:point toView:self.publishButton]; //判斷若是這個這個新的點在自定義按鈕身上,那麼就讓按鈕本身去處理事件; if ([self.publishButton pointInside:newP withEvent:event]) { return self.publishButton; } else { //若是點不在發佈按鈕身上,直接讓系統處理就行了. return [super hitTest:point withEvent:event]; } } else { //tabbar隱藏了,說明push到其餘頁面了,這個時候仍是讓系統去處理就好. return [super hitTest:point withEvent:event]; } }
從今天開始我會將我工做中遇到全部的問題,本身不會的,都會在寫在這裏面:html
有的Bug就一句代碼就可搞定掉的,可是本身知道的有限,共同窗習,共同成長:swift
1.拖拽TableView的時候,鍵盤迴收.(一共有3種模式)windows
tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;安全
2.以前寫的跳轉都是在Vc裏面進行的,還有在自定義cell裏面須要籤協議進行頁面之間的跳轉,如今不用了,你能夠找到你的父視圖的Nab去進行跳轉了,他裏面是do--while 循環找到父視圖,而後進行跳轉的.網絡
- (UIViewController *)viewController { UIResponder *next = [self nextResponder]; do { if ([next isKindOfClass:[UIViewController class]]) { return (UIViewController *)next; } next = [next nextResponder]; } while (next != nil); return nil; }
而後在你須要跳轉的地方寫下下面的代碼就能夠完成頁面之間的跳轉了:app
[[self viewController].navigationController pushViewController:@"想要跳轉的Vc" animated:YES];
這樣就能夠實現了.框架
16.7.14async
今天看了一下之前寫的科大訊飛語音,在模擬器上面能夠運行,放到真機上面就會出現下面的error:ide
若是是其餘的三方平臺也會出現這種錯誤,你也能夠嘗試改下Bitcode;工具
16/07/20:
今天發現個問題就是TextView查看不了層級的問題,一查看層級就會出現:
Assertion failure in -[UITextView _firstBaselineOffsetFromTop], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UITextView.m:1683;
後來在tackoverflow 中找到解決辦法;
http://stackoverflow.com/questions/37068231/assertion-failure-in-uitextview-firstbaselineoffsetfromtop;
就是須要給 textView 建立一個類目, 而後完成這兩個方法就能夠了。
OC版:
@interface UITextView(MYTextView) @end @implementation UITextView (MYTextView) - (void)_firstBaselineOffsetFromTop { } - (void)_baselineOffsetFromBottom { } @end Swift版: extension UITextView { func _firstBaselineOffsetFromTop() { } func _baselineOffsetFromBottom() { } } 這樣就能夠解決這個問題了.
7.27 在今天發現個人項目中全部的NSLog打印,都打不出來結果,緣由工程的模式爲DeBug模式,切換到Release;就能夠了;
提示手機進行振動:
- (void)vibrate { AudioServicesPlaySystemSound(kSystemSoundID_Vibrate); }
設置屏幕在哪些狀況下進行長亮設置:
[[UIApplication sharedApplication] setIdleTimerDisabled:YES]; // 設置播放時屏幕常亮
刪除view上面的全部子視圖:
[self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
2016.08.05 今天在開發者網站上下載證書,提示以下:
證書沒有認證:
證書下載地址:
https://developer.apple.com/certificationauthority/AppleWWDRCA.cer;
點擊連接,下載證書,安裝便可.咱們本身安裝的證書放在鑰匙串的登錄裏面,是蘋果的要放在系統裏面.
2016.08.09 在昨天收到了App被拒的消息,緣由以下:
意思是缺乏一寫隱私,例如舉報,修改以後從新上傳了,而後就進行了加急審覈,建議不要使用加急審覈,若是你須要的話,能夠看下面這篇簡書:
http://www.jianshu.com/p/b359fcf3383b;
UITextField經常使用的鍵盤屬性如:鍵盤類型, 安全輸入等. 其實這些屬性並非UITextField特有的屬性, 而是UITextInputTraits協議屬性(一共有8個屬性).
給UILabel賦HTML5值:
NSString*htmlString = @"<h1>Header</h1><h2>Subheader</h2><p>Some <em>text</em></p><img src='http://blogs.babble.com/famecrawler/files/2010/11/mickey_mouse-1097.jpg' width=70 height=100 />"; NSAttributedString*attributedString = [[NSAttributedStringalloc] initWithData:[htmlString dataUsing Encoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} d ocumentAttributes:nilerror:nil]; textView.attributedText = attributedString;
將文字轉化成拼音:
NSString *_name = @「你麼好」; NSMutableString *pinyin = [_name mutableCopy]; //轉換成拼音 CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformMandarinLatin, NO); //去掉音調 CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformStripDiacritics, NO); NSLog(@"pinyin= %@",pinyin); // 截取首字母 NSString * first = [pinyin substringToIndex:1]; NSLog(@"%@", first);
去除收尾字符串:
NSString *str = @" Liu "; str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
2016.8.31 今天工做工做遇到中文轉碼成GBK:
NSString *pageSource = [[NSString alloc] initWithData:pageData encoding:NSUTF8StringEncoding]; 若是網頁是gbk(或者gb2312),用UTF8轉換的話,pageSource返回nil。這時須要使用gbk編碼作轉換,可是NSStringEncoding不含gbk,怎麼辦?用另外一個方法處理一下: NSStringEncoding gbkEncoding = CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000); NSString *pageSource = [[NSString alloc] initWithData:pageData encoding:gbkEncoding];
2016.09.21 遇到下面這種狀況就是不能使用模擬器運行,的使用真機
2016.09.28 頁面進行跳轉的時候,push,返回按鈕必定要自定義,不要用新系統的,太low爆了.
今天真機測試出現這個錯誤: The certificate used to sign "Programming" has either expired or has been revoked. An updated certificate is required to sign and install the application. 就是說你的證書被別人刪除或者是無效的, 解決方法: 1. command + , 2. 選擇第二個選項 Accounts 3. 在點擊 View Details... 4. 選擇第一個 iOS Development Reset 等待就能夠了
#import "UINavigationBar+Click.h" @implementation UINavigationBar (Click) -(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { self.userInteractionEnabled = [self pointInside:point withEvent:event]; return [super hitTest:point withEvent:event]; } @end
#pragma -- mark -- 切換根視圖控制器動畫 [UIView transitionWithView:[[UIApplication sharedApplication].delegate window] duration:0.4 options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionCurveEaseInOut animations:^{ BOOL oldState = [UIView areAnimationsEnabled]; [UIView setAnimationsEnabled:NO]; WYSLoginViewController *loginVc = [[WYSLoginViewController alloc]init]; WYSCustomNavigationController *naVc = [[WYSCustomNavigationController alloc]initWithRootViewController:loginVc]; [UIApplication sharedApplication].keyWindow.rootViewController = naVc; [UIView setAnimationsEnabled:oldState]; } completion:^(BOOL finished) { }];
#pragma mark -- 開發中咱們須要指定切角爲圓角,就能夠用下面的方法實現. 1.若是是切四個角的圓角,代碼示例: self.picImage.layer.cornerRadius = 8; self.picImage.layer.masksToBounds = YES; 2.若是是四個角中的某幾個角,一個,兩個,或者3個,代碼示例(切的左下,和右下): UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.tipLabel.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = _tipLabel.bounds; maskLayer.path = maskPath.CGPath; self.tipLabel.layer.mask = maskLayer; 類型共有如下幾種: * UIRectCornerTopLeft * UIRectCornerTopRight * UIRectCornerBottomLeft * UIRectCornerBottomRight * UIRectCornerAllCorners
2017--04--10 //這個是切換根視圖控制器動畫 [UIView transitionWithView:[[UIApplication sharedApplication].delegate window] duration:1.0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ BOOL oldState = [UIView areAnimationsEnabled]; [UIView setAnimationsEnabled:NO]; WYSLoginViewController *loginVc = [[WYSLoginViewController alloc]init]; UINavigationController *naVc = [[UINavigationController alloc]initWithRootViewController:loginVc]; [UIApplication sharedApplication].keyWindow.rootViewController = naVc; [UIView setAnimationsEnabled:oldState]; } completion:^(BOOL finished) { }]; } //開發中遇到問題是很正常的,不要去抱怨,那是由於本身的技術仍是不夠成熟,你要用心去看,當你解決一個Bug的時候是很是開心的😁. 今天作登錄部分的細節處理,發如今退出登陸的時候,登錄的頁面向下偏移64px,我就很納悶,這是爲何啊?爲了解決這個Bug,我在退出的時候發送通知去改變登錄View的frame,發現效果不錯,還挺好,在進行跳轉的時候又是一堆Bug,我就鬧心了,後來看了一下,我這個框架是我自定義tabbar,而且設置了navBar的背景圖片,而在切換根式圖的時候,其餘根式圖沒有設置導航欄的背景圖片,致使frame的偏移.後來在設置登錄的背景圖片就行了. (坑會越才越少的, come on);
2017-04-11 公司讓作支付,由於自己項目就有支付,在添加靜態庫.a的時候發現.a中和以前作支付的.a文件存在相同的文件,致使文件衝突,上網查一下資料,很複雜,也有點萌萌噠,一個很簡單的解決方法看下面這張圖片就能夠了:
在第5步添加的時候,就是添加路徑,例如: 項目名稱/文件名/.a 這樣就能夠了,不用謝哈.
開發中經常使用到if--else來進行邏輯判斷,我在collectviewHeader中給頭視圖添加子視圖,判斷是第幾個分區,添加什麼樣的視圖,我用 if -- else if 進行判斷,致使了頭視圖重用了,就是沒有使用else,要記得使用if判斷的時候必定要對應else.(是一個習慣問題);
2017-06-19 :
這個就是push不少頁面,而後POP回到指定頁面,AViewController就是你pop回去的指定的頁面.
for (UIViewController *controller in self.navigationController.viewControllers) { if ([controller isKindOfClass:[AViewController class]]) { AViewController *A =(AViewController *)controller; [self.navigationController popToViewController:A animated:YES]; } }
使用GCD解決,一個頁面請求多個接口數據問題:
方法1.
- (void)groupTest { dispatch_queue_t quete = dispatch_queue_create("XIAXIAQUEUE", DISPATCH_QUEUE_CONCURRENT); dispatch_group_t group = dispatch_group_create(); dispatch_group_enter(group); dispatch_group_async(group, quete, ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ sleep(5); NSLog(@"網絡任務1完----%@", [NSThread currentThread]); dispatch_group_leave(group); }); sleep(2); NSLog(@"任務1完成---%@", [NSThread currentThread]); }); // dispatch_group_wait(group, DISPATCH_TIME_FOREVER); dispatch_group_enter(group); dispatch_group_async(group, quete, ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ sleep(5); NSLog(@"網絡任務2完成----%@", [NSThread currentThread]); dispatch_group_leave(group); }); sleep(2); NSLog(@"任務2完成---%@", [NSThread currentThread]); }); // dispatch_group_wait(group, DISPATCH_TIME_FOREVER); dispatch_group_enter(group); dispatch_group_async(group, quete, ^{ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ sleep(5); NSLog(@"網絡任務3完成 --- %@", [NSThread currentThread]); dispatch_group_leave(group); }); sleep(2); NSLog(@"任務3完成---- %@", [NSThread currentThread]); }); dispatch_group_notify(group, dispatch_get_main_queue(), ^{ NSLog(@"最後執行 ---- %@", [NSThread currentThread]); }); }
方法2.
dispatch_group_t group = dispatch_group_create(); dispatch_async(dispatch_get_global_queue(0, 0), ^{ for (int i = 0; i < 2; i ++) { dispatch_group_enter(group); switch (i) { case 0: { //網絡請求 [self getProductDetailsSuccess:^(BOOL success){ //回調執行 dispatch_group_leave(group); }]; } break; case 1: { //網絡請求 [self getProductEvaluateSuccess:^(BOOL success) { //回調執行 dispatch_group_leave(group); }]; } break; default: break; } } //線程等待 dispatch_group_wait(group, DISPATCH_TIME_FOREVER); dispatch_async(dispatch_get_main_queue(), ^{ //請求完畢,處理業務邏輯 }); });
問題: 若是軟件啓動出現文件損壞 如何操做?
打開終端 ( 終端在 應用程序 - 實用工具內 )
而後藍色內容粘貼下面的內容到窗口內 回車
sudo spctl --master-disable
這個時候就會出現:安全性與隱私->選擇任何來源:
自簽名的過程: 不須要打開Xcode工程 把我提供的zip中libLocationFaker用代碼從新簽名 把.app放到Payload文件夾,壓縮成.ipa 用碼/ fastlane / iresign等工具從新簽名注意:若是證書的BundleID不是*,須要修改Info.plist中的BundleID iTunes / iTools / Xcode安裝ipa,推薦用Xcode安裝,大多數安裝失敗會提示緣由。
修改系統相冊,文字大小,返回按鈕顏色:
#pragma mark -- 修改系統相機導航欄樣式 -(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController* )viewController animated:(BOOL)animated{ if ([navigationController isKindOfClass:[UIImagePickerController class]]){ viewController.navigationController.navigationBar.translucent = NO; viewController.edgesForExtendedLayout = UIRectEdgeNone; viewController.navigationController.navigationBar.barTintColor = [UIColor clearColor]; //title顏色和字體 viewController.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor], NSFontAttributeName:[UIFont systemFontOfSize:18]}; viewController.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor]; viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor]; viewController.navigationController.navigationBar.tintColor = [UIColor whiteColor]; } }
此方法利用反射能夠判斷實體類那些字段爲空:
List<String> list=new ArrayList<String>(); Products products=new Products(); Field[] field =products.getClass().getDeclaredFields(); for (int i=0;i<field.length;i++){ String name = field[i].getName(); name = name.substring(0,1).toUpperCase()+name.substring(1); //將屬性的首字符大寫,方便構造 if(name.contains("_requir")){ Method m = products.getClass().getMethod("get"+name); String value = (String) m.invoke(products);//調用getter方法獲取屬性值 if(value!=null){ list.add(value); }else{ return name+"不能爲空"; } }
TableView滾動到最頂端: [mainTableView scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES]; 或者 [mainTableView setContentOffset:CGPointZero animated:YES]; Swift: mainTableView.setContentOffset(CGPointZero, animated:true) 做者:Jafar 連接:http://www.jianshu.com/p/21b569367548 來源:簡書 著做權歸做者全部。商業轉載請聯繫做者得到受權,非商業轉載請註明出處。
#pragma mark -- 點擊tableBar動畫 - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item { NSLog(@"item name = %@", item.title); NSInteger index = [self.tabBar.items indexOfObject:item]; [self animationWithIndex:index]; if([item.title isEqualToString:@"發現"]) { // 也能夠判斷標題,而後作本身想作的事<img alt="得意" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/proud.gif" /> } } - (void)animationWithIndex:(NSInteger) index { NSMutableArray * tabbarbuttonArray = [NSMutableArray array]; for (UIView *tabBarButton in self.tabBar.subviews) { if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) { [tabbarbuttonArray addObject:tabBarButton]; } } CABasicAnimation*pulse = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; pulse.timingFunction= [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; pulse.duration = 0.2; pulse.repeatCount= 1; pulse.autoreverses= YES; pulse.fromValue= [NSNumber numberWithFloat:0.8]; pulse.toValue= [NSNumber numberWithFloat:1.2]; [[tabbarbuttonArray[index] layer] addAnimation:pulse forKey:nil]; }
工做中,Tabbar中間的按鈕是自定義的,點擊以後模態出來一個頁面,在點擊頁面上面的按鈕Push到下一頁,在下一頁進行調起系統相冊,這時候會報一個錯:Warning: Attempt to present <XXXXPickerController: 0x7fda7d036c00> on <XXXXTabBarController: 0x7fda7bc4fdf0>
whose view is not in the window hierarchy!下面這個方法就能夠解決這個問題, 意思就是模態出來的VC沒有在Window上面,也就是沒有根視圖.
//取當前最上面的presentedViewController UIViewController * topVc = [UIApplication sharedApplication].keyWindow.rootViewController; while (topVc.presentedViewController) { topVc = topVc.presentedViewController; } [topVc presentViewController:picker animated:YES completion:nil];
查看工程中的第三方是否使用IDFA: 1.用終端cd到項目目錄. 2.grep -r advertisingIdentifier . (注意後面這個 "." 必定要有啊!!!!)
//搜索關鍵字高亮: #pragma mark -- 關鍵字高亮 - (NSAttributedString *)highlightText:(NSString *)keyword inStr:(NSString *)str { NSRange range = [str rangeOfString:keyword]; NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:str]; if (range.length > 0) { [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:range]; } else { [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor darkGrayColor] range:range]; } return [[NSAttributedString alloc]initWithAttributedString:attrStr]; }
//獲取字符串中的電話號碼 NSString *regulaStr = @"\\d{3,4}[- ]?\\d{7,8}"; NSRange stringRange = NSMakeRange(0, ridePhoneNum.length); //正則匹配 NSError *error; NSMutableAttributedString *str = [[NSMutableAttributedString alloc]initWithString:ridePhoneNum]; NSRegularExpression *regexps = [NSRegularExpression regularExpressionWithPattern:regulaStr options:0 error:&error]; if (!error && regexps != nil) { [regexps enumerateMatchesInString:ridePhoneNum options:0 range:stringRange usingBlock:^(NSTextCheckingResult * _Nullable result, NSMatchingFlags flags, BOOL * _Nonnull stop) { NSRange phoneRange = result.range; //定義一個NSAttributedstring接受電話號碼字符串 _phoneNumber = [str attributedSubstringFromRange:phoneRange]; //添加下劃線 NSDictionary *attribtDic = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]}; [str addAttributes:attribtDic range:phoneRange]; //設置文本中的電話號碼顯示爲黃色 [str addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:phoneRange]; _labelManIphoneNumShow.attributedText = str; _labelManIphoneNumShow.userInteractionEnabled = YES; //添加手勢,能夠點擊號碼撥打電話 UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGesture:)]; [_labelManIphoneNumShow addGestureRecognizer:tap]; }]; }
//解決UIScroller與FDFullscreenPopGesture 手勢衝突, 意思是scroller的偏移量<=0的時候,讓他去響應_FDFullscreenPopGestureRecognizerDelegate - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { if (self.contentOffset.x <= 0) { if ([otherGestureRecognizer.delegate isKindOfClass:NSClassFromString(@"_FDFullscreenPopGestureRecognizerDelegate")]) { return YES; } } return NO; }
獲取當前屏幕顯示的VC: +(UIViewController *)getCurrentVC { UIViewController *result = nil; UIWindow *window = [[UIApplication sharedApplication] keyWindow]; if (window.windowLevel != UIWindowLevelNormal) { NSArray *windows = [[UIApplication sharedApplication] windows]; for (UIWindow *tmpWin in windows) { if (tmpWin.windowLevel == UIWindowLevelNormal) { window = tmpWin; break; } } } UIView *frontView = [[window subviews] objectAtIndex:0]; id nextResponder = [frontView nextResponder]; if ([nextResponder isKindOfClass:[UIViewController class]]) result = nextResponder; else result = window.rootViewController; return result; }
日期驗證: NSString *regex = @"([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3}).(((0[13578]|1[02]).(0[1-9]|[12][0-9]|3[01]))|((0[469]|11).(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))";
// (([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3}).(((0[13578]|1[02]).(0[1-9]|[12][0-9]|3[01]))|((0[469]|11).(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00)).02.29) NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex]; if ([pred evaluateWithObject:str]) { return YES; } return NO;
處理HTML文字,去除標籤,竊取字符串 NSString *htmlString = [self getNormalStringFilterHTMLString:_content]; NSArray *firArray = [htmlString componentsSeparatedByString:@"【"]; for (NSString *NextStr in firArray) { if ([NextStr isEqualToString:@""] || NextStr == nil) { } else { WYSGoodsDetailProductManualModel *model = [[WYSGoodsDetailProductManualModel alloc]init]; NSArray *lastArray = [NextStr componentsSeparatedByString:@"】"]; model.titelMa = [lastArray firstObject]; model.contentMa = [lastArray lastObject]; [_arrayKey addObject:model]; } } [self.tableViewManual reloadData]; //對字符串進行處理 -(NSString *)getNormalStringFilterHTMLString:(NSString *)htmlStr{ NSString *normalStr = htmlStr.copy; //判斷字符串是否有效 if (!normalStr || normalStr.length == 0 || [normalStr isEqual:[NSNull null]]) return nil; //過濾正常標籤 NSRegularExpression *regularExpression=[NSRegularExpression regularExpressionWithPattern:@"<[^>]*>" options:NSRegularExpressionCaseInsensitive error:nil]; normalStr = [regularExpression stringByReplacingMatchesInString:normalStr options:NSMatchingReportProgress range:NSMakeRange(0, normalStr.length) withTemplate:@""]; //過濾佔位符 NSRegularExpression *plExpression=[NSRegularExpression regularExpressionWithPattern:@"&[^;]+;" options:NSRegularExpressionCaseInsensitive error:nil]; normalStr = [plExpression stringByReplacingMatchesInString:normalStr options:NSMatchingReportProgress range:NSMakeRange(0, normalStr.length) withTemplate:@""]; //過濾空格 NSRegularExpression *spaceExpression=[NSRegularExpression regularExpressionWithPattern:@"^\\s*|\\s*$" options:NSRegularExpressionCaseInsensitive error:nil]; normalStr = [spaceExpression stringByReplacingMatchesInString:normalStr options:NSMatchingReportProgress range:NSMakeRange(0, normalStr.length) withTemplate:@""]; return normalStr; }
持續更新............