xcode9 xib文件搭建过程中的坑

2018-08-31

tableView有一个bounces属性。默认YES,所以tableView上下用力拉都会有弹性滑动,如下设置可以禁止,但是这样的话上下弹性都没了

有时的需求是上方不要弹性,下方要弹性,可以用监听,只要是小于0就是弹性发生的情况,手动设置0禁止即可,如果有x偏转需要先去除x再放上去,同理只取消下方弹性理论上这种思路应该也可以

- (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView == self.tableView) { CGFloat offY = scrollView.contentOffset.y; if (offY < 0) { scrollView.contentOffset = CGPointZero; } } }

但是一般情况下我们只要设置tableView的Clip to Bounds为YES就可以了,这样跑到frame外面的内容就看不到了,弹性也有了

——————————————————————————————————————

*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSObject 0x141d09110> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key notiSubtitleLabel.'

连线的时候注意选择,不要选择firstResponse,要选择这个类的名字。

xib搭建cell

拉入一个UITableViewCell,注意这个cell有一个尺寸,一定要设置否则不能自动布局,

Cell中还有一个View,这个View就是superView,一定要设置,跟cell一个尺寸。另外切记要给这个View设置到他的superViewde边框为(0,0,0,0)

 [_tvDevicesList registerNib:[UINib nibWithNibName:@“AllDeviceListTableView" bundle:nil] forCellReuseIdentifier:allDeviceListTableViewCellIdentifier];

通过cell注册TableView,可以把自定义cell与TableView连接起来。NibName:xib文件名

CellReuseIdentifier:给cell取的Identifier

cell的xib文件只要把class改为 cell的.h/或者.swift的类名就可以联通

!!! 连线之后不要修改,如果需要修改,要重新写xib文件以及类文件,要不然就会报上面的错,不重新写文件很难找到问题

图片导入不显示,B一下,还不能显示清缓存,  再不行删除后重新导入

,选择adjusts会影响代码对button图片与文字的布局

button.titleEdgeInsets = UIEdgeInsetsMake(0,-(button.currentImage?.size.width)!, (button.titleLabel?.intrinsicContentSize.height)! - button.height()/2, 0)

button.imageEdgeInsets = UIEdgeInsetsMake(-(button.titleLabel?.intrinsicContentSize.height)!, 0, 0, -(button.titleLabel?.intrinsicContentSize.width)!)

猜你喜欢

转载自blog.csdn.net/weixin_39872861/article/details/80408969
今日推荐