iOS常用知識ポイントまとめ

5934 ワード

0.setメソッドが割り当てられない

  • 他に関係なくsd_Layoutフレームワークのframe設定に問題があります.

  • 1.親コントロールの子viewを削除する

    [self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]; 
    

    2.Xcode log不完全

    #ifdef DEBUG
    #define CSLog(format, ...) printf("class:  method: %s 
    %s
    ", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(format), ##__VA_ARGS__] UTF8String] ) #else #define CSLog(format, ...) #endif

    3.UIIMage画像の引き伸ばし方法

    - (UIImage *)resizableImage:(NSString *)name
    {
        UIImage *image = [UIImage imageNamed:name];
        return [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
    }
    

    4.文字列切り取り情報

    NSUInteger loc = [string rangeOfString:@"\":\""].location + 3;
    NSUInteger len = [string rangeOfString:@"\"}"].location - loc;
    NSString *msg = [string substringWithRange:NSMakeRange(loc, len)];
    

    5.URLの中国語変換

    NSString *encodedString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    //  
    NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:name1];
    NSString *abc = [name1 stringByAddingPercentEncodingWithAllowedCharacters:set];
    
  • 復号:str文字列をUTF-8規則で復号し、UTF-8変換中国語
  • [str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    //   
    str.stringByRemovingPercentEncoding
    //////////
    NSString *urlStr = [NSString stringWithFormat:@"http://localhost/login?username= &pwd=123"];  
    urlStr = [urlStr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];  
    

    6.配列順と追加時に来る

    NSArray* reversedArray = [[self.keyRecordData reverseObjectEnumerator] allObjects];
    

    7.キーボードを終了

     [self.view endEditing:YES];
    
     [self.messageField resignFirstResponder];
    
     [self.messageField endEditing:YES];
    

    8.電話をかける

     NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",twoModel.UserPhone];
     UIWebView *callWebview = [[UIWebView alloc] init];
     [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
     [self.view addSubview:callWebview];
    

    9.バージョン番号の取得

    NSString *appVersion =[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    

    10. __weak

    __weak UITextField * weakTf = textField;
    

    11文字の高さを取得

    CGFloat h = [model.message boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width - kGAP-kAvatar_Size - 2*kGAP, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes context:nil].size.height+0.5;
    

    12 section

     _dataArray = @[@{ @"key":@" ",
                              @"value":@[@" ",@" ",@" ",@" (cm)",@" (kg)"],
                              },
                           @{ @"key":@" ",
                              @"value":@[@" / ",@" "],
                              },
                           @{ @"key":@" ",
                              @"value":@[@" ",@" ",@" "],
                              },
                           @{ @"key":@" ",
                              @"value":@[@" ",@" "],
                              }
                           ];
    

    13 xibを使用してlabelにショートカットを折り返す

  • option +reutrn

  • 14スペースのフィルタ

     // 
        NSString *textString = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    

    15 absoluteString

    NSURL *url = [NSURL URLWithString:@"http://www.baidu.com/search?id=1"];
    2
        NSLog(@"scheme:%@", [url scheme]); //  http
    3
        NSLog(@"host:%@", [url host]);     //  www.baidu.com
    4
        NSLog(@"absoluteString:%@", [url absoluteString]); // url  http://www.baidu.com:8080/search?id=1   ( ,  8080  )
    5
        NSLog(@"relativePath: %@", [url relativePath]); //  search
    6
        NSLog(@"port :%@", [url port]);  //   8080
    7
        NSLog(@"path: %@", [url path]);  //   search
    8
        NSLog(@"pathComponents:%@", [url pathComponents]); // search
    9
        NSLog(@"Query:%@", [url query]);  //  id=1
    

    16 UIcollectionView flowlayout固定itemの設定

     
        CGFloat margin = (kScreenWidth - ZKCommonCollectionHW *3)/4.0;
        //  ( )  
        flowLayout.minimumLineSpacing = margin;
        // cell cell ( )  
        flowLayout.minimumInteritemSpacing = margin;
        flowLayout.itemSize = CGSizeMake(ZKCommonCollectionHW,ZKCommonCollectionHW);
       //  collectionView     
        flowLayout.sectionInset = UIEdgeInsetsMake(margin, margin, margin*3 , margin);
    
    //  sdlayout  frame    insert  3 。
     
     _collectionView.sd_layout.spaceToSuperView(UIEdgeInsetsZero);
     
       flowLayout.sectionInset = UIEdgeInsetsMake(margin, margin, margin , margin);
    

    17 APPの初回と更新後の起動

    // NO  
    - (BOOL)hasLaunched {
        
        NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        if (![[userDefaults objectForKey:@"version"] isEqualToString:version]) {
            [userDefaults setObject:version forKey:@"version"];
            return NO;
        }else {
            return YES;
        }
    }