IOS用戶端Coding項目記錄(四),ios用戶端coding項目

來源:互聯網
上載者:User

IOS用戶端Coding項目記錄(四),ios用戶端coding項目

1:開啟Xcode,然後閃退,報載入某庫出現異常

如/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libclang.dylib這個是Xcode的bug,我的情況是開啟某個項目會出現這個問題解決辦法:這還是緩衝問題,詳見第五點(5、XCode5由於緩衝問題引起了很多奇怪的問題,所以清除緩衝有時會起到大作用:),清除緩衝再運行,一切正常。進入步驟,按option鍵進入資產庫,Developer—xcode—DerivedData把裡面的檔案清除就可以

2:加快CocoaPod安裝外掛程式的速度

(這樣也解決一些外掛程式下載時失敗的問題,因為一些原始碼的內容是不必要,而提供的地址卻串連不到,導致報錯,而無法更新)$ pod install --no-repo-update 

3:userInteractionEnabled屬性

當視圖對象的userInteractionEnabled設定為NO的時候,使用者觸發的事件,如觸摸,鍵盤等,將會被該視圖忽略(其他視圖照常響應),並且該視圖對象也會從事件響應隊列中被移除。 當userInteractionEnabled設為YES時,則事件可以正常的傳遞給該視圖對象。 userInteractionEnabled的屬性預設值就是YES。EaseUserHeaderView *headerView = [[EaseUserHeaderView alloc] init];headerView.userInteractionEnabled = YES;

4:字串顯示問題,同一行不同的效果

調用:[_fansCountBtn setAttributedTitle:[self getStringWithTitle:@"粉絲" andValue:_curUser.fans_count.stringValue] forState:UIControlStateNormal];方法:- (NSMutableAttributedString*)getStringWithTitle:(NSString *)title andValue:(NSString *)value{    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ %@", value, title]];    [attriString addAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:17],                                 NSForegroundColorAttributeName : [UIColor whiteColor]}                         range:NSMakeRange(0, value.length)];        [attriString addAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14],                                 NSForegroundColorAttributeName : [UIColor whiteColor]}                         range:NSMakeRange(value.length+1, title.length)];    return  attriString;}另:label可以調用sizeToFit來調整內容適應_userLabel.text = _curUser.name;[_userLabel sizeToFit];

5:NSArray中使用firstObject和lastObject

NSArray有lastObject方法用來擷取數組最後一個對象,firstObject來擷取數組第一個對象,NSArray中使用firstObject和lastObject的好處在於,當數組為空白時,返回nil,而不會報錯。當數組為空白,使用myArray[0]時,會報錯。NSNumber *firstLevel = nil, *secondLevel = nil;NSArray *locationArray = [_curUser.location componentsSeparatedByString:@" "];                        if (locationArray.count == 2) {                            firstLevel = [AddressManager indexOfFirst:[locationArray firstObject]];                            secondLevel = [AddressManager indexOfSecond:[locationArray lastObject] inFirst:[locationArray firstObject]];                        }

6:日期控制項ActionSheetDatePicker  多級控制項ActionSheetStringPicker

小執行個體:                    NSDate *curDate = [NSDate dateFromString:_curUser.birthday withFormat:@"yyyy-MM-dd"];                    if (!curDate) {                        curDate = [NSDate dateFromString:@"1990-01-01" withFormat:@"yyyy-MM-dd"];                    }                    ActionSheetDatePicker *picker = [[ActionSheetDatePicker alloc] initWithTitle:nil datePickerMode:UIDatePickerModeDate selectedDate:curDate doneBlock:^(ActionSheetDatePicker *picker, NSDate *selectedDate, id origin) {                        NSString *preValue = weakSelf.curUser.birthday;                        weakSelf.curUser.birthday = [selectedDate string_yyyy_MM_dd];                        [weakSelf.myTableView reloadData];                        [[Coding_NetAPIManager sharedManager] request_UpdateUserInfo_WithObj:weakSelf.curUser andBlock:^(id data, NSError *error) {                            if (data) {                                weakSelf.curUser = data;                            }else{                                weakSelf.curUser.birthday = preValue;                            }                            [weakSelf.myTableView reloadData];                        }];                    } cancelBlock:^(ActionSheetDatePicker *picker) {                        NSLog(@"%@", picker.description);                    } origin:self.view];                    picker.minimumDate = [[NSDate date] offsetYear:-120];                    picker.maximumDate = [NSDate date];                    [picker showActionSheetPicker];小執行個體:[ActionSheetStringPicker showPickerWithTitle:nil rows:@[[AddressManager firstLevelArray], [AddressManager secondLevelMap]] initialSelection:@[firstLevel, secondLevel] doneBlock:^(ActionSheetStringPicker *picker, NSArray * selectedIndex, NSArray *selectedValue) {                        NSString *preValue = weakSelf.curUser.location;                        NSString *location = [selectedValue componentsJoinedByString:@" "];                        weakSelf.curUser.location = location;                        [weakSelf.myTableView reloadData];                        [[Coding_NetAPIManager sharedManager] request_UpdateUserInfo_WithObj:weakSelf.curUser andBlock:^(id data, NSError *error) {                            if (data) {                                weakSelf.curUser = data;                            }else{                                weakSelf.curUser.location = preValue;                            }                            [weakSelf.myTableView reloadData];                        }];                    } cancelBlock:nil origin:self.view];小執行個體:[ActionSheetStringPicker showPickerWithTitle:nil rows:@[@[@"男", @"女", @"未知"]] initialSelection:@[_curUser.sex] doneBlock:^(ActionSheetStringPicker *picker, NSArray * selectedIndex, NSArray *selectedValue) {                        NSNumber *preValue = weakSelf.curUser.sex;                        weakSelf.curUser.sex = [selectedIndex firstObject];                        [weakSelf.myTableView reloadData];                        [[Coding_NetAPIManager sharedManager] request_UpdateUserInfo_WithObj:weakSelf.curUser andBlock:^(id data, NSError *error) {                            if (data) {                                weakSelf.curUser = data;                            }else{                                weakSelf.curUser.sex = preValue;                            }                            [weakSelf.myTableView reloadData];                        }];                    } cancelBlock:nil origin:self.view];

7:代碼自動布局Masonry外掛程式

Masonry支援哪一些屬性@property (nonatomic, strong, readonly) MASConstraint *left;@property (nonatomic, strong, readonly) MASConstraint *top;@property (nonatomic, strong, readonly) MASConstraint *right;@property (nonatomic, strong, readonly) MASConstraint *bottom;@property (nonatomic, strong, readonly) MASConstraint *leading;@property (nonatomic, strong, readonly) MASConstraint *trailing;@property (nonatomic, strong, readonly) MASConstraint *width;@property (nonatomic, strong, readonly) MASConstraint *height;@property (nonatomic, strong, readonly) MASConstraint *centerX;@property (nonatomic, strong, readonly) MASConstraint *centerY;@property (nonatomic, strong, readonly) MASConstraint *baseline;小執行個體:        if (!_titleL) {            _titleL = [[UILabel alloc] init];            [self.contentView addSubview:_titleL];            _titleL.font = [UIFont systemFontOfSize:16];            _titleL.textColor = [UIColor blackColor];        }        if (!_valueL) {            _valueL = [[UILabel alloc] init];            _valueL.numberOfLines = 0;            [self.contentView addSubview:_valueL];            _valueL.font = [UIFont systemFontOfSize:15];            _valueL.textColor = [UIColor colorWithHexString:@"0x999999"];        }                [_titleL mas_makeConstraints:^(MASConstraintMaker *make) {            make.left.equalTo(self.contentView).offset(kPaddingLeftWidth);            make.height.mas_equalTo(20);            make.top.equalTo(self.contentView).offset(12);            make.width.mas_equalTo(kScreen_Width - 2*kPaddingLeftWidth);        }];        [_valueL mas_makeConstraints:^(MASConstraintMaker *make) {            make.top.equalTo(_titleL.mas_bottom).offset(12);            make.left.right.equalTo(_titleL);        }];好文章:http://www.cocoachina.com/ios/20141219/10702.html

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.