你的位置:首页 > 操作系统

[操作系统]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