iOS开发中遇到的一些问题
UILabel使用attribute string时,显示单行文字时,计算出的高度不太正常,底部会多出行间距(lineSpacing);多行时,就是正常的。
解决方法: 在attributes字典中,只在文字展示为多行的情况下设置NSParagraphStyleAttributeName。
1  |  | 
在Storyboard中使用了静态cell,cell包含auto layout约束,关联了IBOutlet,然后设置其accessoryView,导致CPU使用率飚升,界面卡死
解决方法: 不使用accessoryView,直接将对应的视图放在静态cell中,并添加相关的约束
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "XXX" nib but the view outlet was not set.'
解决方法: 在xib文件中添加一个View,而不是一个ViewController。File's Owner对应的Class应为自定义视图控制器的Class
控制台警告Setting the background color on UITableViewHeaderFooterView has been deprecated. Please use contentView.backgroundColor instead.
解决方法: 如果使用的是xib或storyboard,把backgroudColor设置为default就行了。
如果使用的是代码,将设置其backgroundColor的代码删掉。
如果必须设置backgroundColor,需要创建一个view,设置该view的backgroundColor,并将其赋给backgroundView属性。
UITableView的tableHeaderView或tableFooterView位置不正确(与cell重叠)
解决方法: 必须在给这两个属性赋值之前设置frame(设置bounds是不行的)。
如果是从xib创建视图,对象假定为xibView,必须init另一个视图,对象假定为wrapView,然后将xibView添加到wrapView上,再将wrapView赋给tableHeaderView或tableFooterView。
1  |  | 
自定义UITableViewHeaderFooterView背景色问题
自定义UITableViewHeaderFooterView,设置了其contentView的背景色,在不低于iOS 10的系统上是有效的,但在iOS 8、iOS 9上是透明的。
解决方案:
1  |  | 
iOS开发中遇到的一些问题
      https://daniate.github.io/2022/04/10/iOS开发中遇到的一些问题/