新开一个周总结,为了记录每周在开发中遇到的问题。
由于前几周比较忙,只是记录了问题,没有写出博客,补录。
时间:2018.11.26-2018.12.01
1.纯代码写collectionViewCell
如上所述,近期我一直使用纯代码写工程,在创建collectionViewCell时遇到了一个小问题。
纯代码在tableViewCell中我们使用下面的方法来添加子视图。
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.selectionStyle = UITableViewCellSelectionStyleNone; [self createSubViews]; } return self; }
可是在collectionViewCell中没有这个方法。我试了init、initWithCoder方法都不能添加子视图。后来才发现它走的是frame。应该调用下面的方法。
- (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self createSubViews]; } return self; }
SDCycleScrollView中也是这样创建的。详见SelectVideoImageCollectionViewCell中。
个人推测因为collectionViewCell有具体的大小,会调用这个方法。
2.禁止某个单独页面侧滑返回。
在iOS中有侧滑返回的功能,但是在某些界面中我们不需要这个功能。那么如何单独禁止呢?
-(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = NO; } } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) { self.navigationController.interactivePopGestureRecognizer.enabled = YES; }; }
这个方法就可以实现这个功能了,但是如果你使用了一下自定义的导航栏可能会不管用。就像我使用了RTRootNavigationController这个第三方导航栏管理。使用了上面的方法不能实现这个功能。后来看源码发现,作者已经考虑了这个问题直接使用源码中的属性方法就可以了。
self.rt_disableInteractivePop = true; self.rt_navigationController.rt_disableInteractivePop = true;
3.在开发中也会遇到输出%的时候。在我们直接打出%就像下面的情况,会出现警告。
self.leftTitleLabel.text = [NSString stringWithFormat:@"%@%-%@%",model.minLoanInterest,model.maxLoanInterest];
那么如何解决这个问题,就很简单。就像下面打出%%就行。
self.leftTitleLabel.text = [NSString stringWithFormat:@"%@%%-%@%%",model.minLoanInterest,model.maxLoanInterest];
4.图表使用
在本周开发中遇到了折线图。之前没有专门研究过。在这周研究了一下。
发现了两个不错的三方库。charts、AAChartKit。后面会单独开一个博客介绍着两个。
5.storyboard上创建tabbarcontroller上item数量
纯代码创建tabbarcontroller很简单,我们之前一般都是这样做的。在我们写demo的时候想要快捷方便的做出效果,那么storyboard就是很不错的选择。在现在的xcode中,设置为tabbarcontroller后默认创建的item数量是1,如何增加呢?
请看图
下面就是关键了,右键tabbarcontroller
这就完成了,tabbarcontroller上就有两个item了。