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
时间: 2024-08-11 01:26:01

IOS客户端Coding项目记录(四)的相关文章

IOS客户端Coding项目记录(三)

18:图片视图几种填充样式 _imgView.contentMode = UIViewContentModeScaleAspectFill; 如下: typedef NS_ENUM(NSInteger, UIViewContentMode) { UIViewContentModeScaleToFill, UIViewContentModeScaleAspectFit, UIViewContentModeScaleAspectFill, UIViewContentModeRedraw, // re

IOS客户端Coding项目记录(一)

1:UITextField设置出现清除按键 self.textField.clearButtonMode = UITextFieldViewModeWhileEditing; 说明: UITextField.clearButtonMode:清空输入的字符,有以下几种模式 UITextFieldViewModeAlways,不为空,获得焦点与没有获得焦点都显示清空按钮 UITextFieldViewModeNever,不显示清空按钮 UITextFieldViewModeWhileEditing,

IOS客户端Coding项目记录(五)

1:统一修改导航栏的样式,在 AppDelegate.m中 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customiz

IOS客户端Coding项目记录(二)

9:第三方插件整理 JSON转实体:jsonModel https://github.com/icanzilb/JSONModel/ 美化按键:BButton https://github.com/mattlawer/BButton 状态栏提示:JDStatusBarNotification https://github.com/jaydee3/JDStatusBarNotification 照片显示插件:MJPhotoBrowser https://github.com/azxfire/MJP

ios客户端暑期“动画屋“活动项目总结

    入职实习的这个公司,第一天就分配了任务,从零开始写一个网页,之前虽然了解一些前端知识,但从头开写还是遇到了很多问题,互联网公司讲求效率,有deadline还是比较有紧迫感的,与在实验室放羊状态有了鲜明的对比.mentor.产品经理.组里的boss.实习生同事都给我提供了非常多的帮助.此篇总结为独立完成的第一个项目的项目总结.下图是已上线活动界面效果. 项目介绍 (一).爱奇艺IOS客户端发现-活动页面中"动画屋"活动开始页面的开发     活动开始页面的开发主要需求是:    

ios客户端发现_世界杯送流量活动项目总结

   世界杯如火如荼的进行,视频网站类似于门户网站,需要快速根据外部环境更新内容.产品经理需要策划活动,并安排实施.这个活动就是在这样背景下产生的,爱奇艺与运营商合作,实现双赢.爱奇艺可以通过运营商向海量用户发送短信的方式,提高用户数,运营商通过爱奇艺视频平台给用户更多种多样的福利,提高用户黏性.   总的来说:运营商有用户,视频网站有内容.用户需要内容,有内容的需要用户,有用户的需要满足用户内容的需求.两者优点突出.需求明显合作水到渠成.另外爱奇艺将运营商作为大客户管理,保证了协同作战的机动性

iOS开发——完整项目实战OC篇&百思不得姐第四天

iOS开发——完整项目实战OC篇&百思不得姐第四天 上午 一:自定义按钮使用九宫格布局 二:控件不能点击 三:获取用户点击了那个按钮 四:调整按钮内部控件的位置:主流->上下 五:不能直接使用self.navigationController中或者View中获取导航控制器 方法一: 方法二: 六:布局取整 1 // 总行数 2 3 // NSUInteger rows = sqaures.count / maxCols; 4 5 // if (sqaures.count % maxCols)

ios客户端发现_动画屋后期页面重构与悬浮评论分享模块开发项目总结

从"看世界杯送流量"项目,遇到响应式布局问题之后,专门钻研了这方面专业的书籍,同时阅读了相关文章.响应式布局简单的说就是使开发的页面在不同设备上都有友好的效果.而最开始"暑期动画屋"的项目,当时并没有采用响应式布局,虽然ipad上可用,其他设备则会有显示问题.这也暴露了,目前所在移动业务事业部前端的问题:    1.考虑到响应式布局在不同设备上,UI设计师只给了一套UI原型图,而在不同设备上的显示只是根据前端工程师的理解或个人偏好来完成布局.从产品经理的角度以及测试

iOS 开源项目(四)

1.AFNetworking 在众多iOS开源项目中,AFNetworking可以称得上是最受开发者欢迎的库项目.AFNetworking是一个轻量级的iOS.Mac OS X网络通信类库,现在是GitHub上第三大Objective-C库.它建立在NSURLConnection.NSOperation等类库的基础上,让很多网络通信功能的实现变得十分简单,因此,许多iOS应用开发都会使用到它. 支持HTTP请求和基于REST的网络服务(包括GET.POST.PUT.DELETE等): 支持ARC