mark! 細節整理,記錄問題

判斷字符串是否是合法的郵箱地址

-(BOOL) NSStringIsValidEmail:(NSString *)checkString
{
   BOOL stricterFilter = YES; // Discussion http://blog.logichigh.com/2010/09/02/validating-an-e-mail-address/
   NSString *stricterFilterString = @"[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}";
   NSString *laxString = @".+@([A-Za-z0-9]+\\.)+[A-Za-z]{2}[A-Za-z]*";
   NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
   NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
   return [emailTest evaluateWithObject:checkString];
}

計算兩個日期之間相差幾天幾小時幾分鐘
用timeIntervalSinceDate得到日期之間相差的秒數,然後再轉換成天數小時和分
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
   
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit |
    NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
     comps=[calendar components:unitFlags fromDate:date toDate:date options:0];
    NSLog(@"%@",comps);
   // comps = [calendar components:unitFlags fromDate:date];


NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];
   [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
   NSDate *  senddate=[NSDate date];
   //結束時間
   NSDate *endDate = [dateFormatter dateFromString:@"2014-6-24 00:00:00"];
   //當前時間
   NSDate *senderDate = [dateFormatter dateFromString:[dateFormatter stringFromDate:senddate]];
   //得到相差秒數
   NSTimeInterval time=[endDate timeIntervalSinceDate:senderDate];
    
   int days = ((int)time)/(3600*24);
   int hours = ((int)time)%(3600*24)/3600;
   int minute = ((int)time)%(3600*24)600/60;
   
   if (days <= 0&&hours; <= 0&&minute; <= 0)
       dateContent=@"0天0小時0分鐘";
   else
       dateContent=[[NSString alloc] initWithFormat:@"%i天%i小時%i分鐘",days,hours,minute];

刷新某行cell的方法

NSIndexPath *indexPath_1=[NSIndexPath indexPathForRow:indePath.row inSection:0];
      NSArray *indexArray=[NSArray  arrayWithObject:indexPath_1];
      [myTableView  reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationAutomatic];

iOS7上tableView的分割線左邊短了一點

ios7裏面tableViewCell上面的分割線,左邊少了20個像素,用下面的方法,可以讓分割線完整顯示出來
if ([_tableView respondsToSelector:@selector(setSeparatorInset:)]) {
           [_tableView setSeparatorInset:UIEdgeInsetsZero];
       }

改變狀態欄字體顏色

1.在info.plist裏面添加字段
key----View controller-based status bar appearance
value---NO
 
在appDelegate裏面添加代碼:
 [[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
 
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];

如何讓textField輸入框 限制輸入字數的同時,還只讓輸入數字和字母

//UITextFieldDelegate  
- (BOOL)textFieldShouldReturn:(UITextField *)textField;  
{  
    //用戶結束輸入  
    [textField   resignFirstResponder];  
   
    return  YES;  
}  
 
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string   // return NO to not change text  
{  
    //判斷是否超過 ACCOUNT_MAX_CHARS  個字符,注意要判斷當string.leng>0  
    //的情況纔行,如果是刪除的時候,string.length==0  
    int length = textField.text.length;  
    if (length >= ACCOUNT_MAX_CHARS  &&  string.length >0)  
    {  
        return  NO;  
    }  
       
       
    NSCharacterSet *cs;  
    cs = [[NSCharacterSet characterSetWithCharactersInString:kAlphaNum] invertedSet];  
    NSString *filtered =  
    [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];  
    BOOL basic = [string isEqualToString:filtered];  
    return basic;  
}

企業版ipa安裝方法

訪問my.html,通過itms-services協議跳轉到my.plist實現下載安裝my.ipa 
相關my.ipa設置需修改my.plist文件

/*網頁部分 "my.html"*/
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd" >
<html>
  <head>
    <title>安裝我的應用</title>
  </head>
  <body>
    <a href='itms-services://?action=download-manifest&url=http://192.168.1.123:8080/ipa.plist'>安裝我的應用</a>
  </body>
</html>
/*plist文件部分 my.plist*/
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
   <key>items</key>
   <array>
       <dict>
           <key>assets</key>
           <array>
               <dict>
                   <key>kind</key>
                   <string>software-package</string>
                   <key>url</key>
                   <string>http://192.168.1.123:8080/ipa/my.ipa</string>
               </dict>
               <dict>
                   <key>kind</key>
                   <string>display-image</string>
                   <key>needs-shine</key>
                   <true/>
                   <key>url</key>
                   <string>http://192.168.1.123/ipa/icon_120.png</string>
               </dict>
        <dict>
                   <key>kind</key>
                   <string>full-size-image</string>
                   <key>needs-shine</key>
                   <true/>
                   <key>url</key>
     <string>http://192.168.1.123:8080/ipa/icon_120.png</string>
               </dict>
           </array><key>metadata</key>
           <dict>
               <key>bundle-identifier</key>
               <string>com.my.myapp</string>
               <key>bundle-version</key>
               <string>1.0.0</string>
               <key>kind</key>
               <string>software</string>
               <key>subtitle</key>
               <string>我的應用</string>
               <key>title</key>
               <string>我的應用</string>
           </dict>
       </dict>
   </array>
</dict>
</plist>










發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章