今天项目中又出现了之前遇到的一个问题,虽说之前解决的,现在还是花了一些时间才想起来解决办法,故在此记录一下。
之前遇到的问题是用storyboard创建了一个UIViewController,然后再UIViewController中添加一个UITableView,在真机调试时,总是出现最后一个cell不能显示,拼命往上拽是可以看到的,但是一松手有下去不见了。虽然在代码中修改了tableview的frame属性,打印出来tableview的高度也是对的,但是还是会出现这问题。
今天遇到的问题是在xib中创建的界面,问题还是一模一样。
原因:这是ios7及7.0以后遇到的一个页面布局的问题,苹果默认选中了autolayout属性,就是自动布局,所以才造成的这个bug
解决办法:
xib文件
打开xib文件,然后在右边的属性表中点击最左边的属性页面,如图1。
在Interface Builder Document中最下面有个选项 Use Autolayout,默认是选中的,去掉就好了。
一定要注意是修改最左边的属性页(file inspector),不是左边第三个(size inspector)。
然后就是可以同过修改tableview的frame来控制tableview的位置了。
storyboard中的也是一样的。
同样是打开storyboard文件,然后修改最左边的file inspector属性页。找到Use Autolayout,去掉选中即可。下一步就是设置控件的frame啦,相信大家都会的。