iOS storyboard 任意使用static tableView

iOS storyboard 任意使用static tableView

iOS的布局中,可以使用 static tableView cell即无需编程,直在在sb中一个一个画出cell的布局来,这是真正的所见即所得。

这种方法在UITableViewController 对应的窗口很好用,但是如果你想美化一下界面,比如想把TableView 加入到另一个View中,上下加点标题之类美化。 此时也是能设计出效果,但是执行时会提示编译错误:

error: Illegal Configuration: Static table views are only valid when embedded in UITableViewController instances

怎么办?

解决办法

有人提到的解决办法是曲线设计,即先做一个tableViewController然后再把这个view 嵌入到你真正需要显示的view当中:

http://stackoverflow.com/questions/22364230/static-table-view-outside-uitableviewcontroller

原文内容如下:

  • Drag a ViewController onto your storyboard.
  • Drag a TableViewController onto your storyboard.
  • Next Drag a Container view to your ViewController and size it about the size you want (smaller than the view) -> when you drag the container view it will create a segue and another view. Remove that segue and view.
  • Then finally ctrl click in your container and drag to your new TableViewContoller. Select Embed.
  • Style your TableView the way you want -> including static cells.

翻译意思如下
你真正显示是storyboard中一个viewController,假设为viewA
为了使用静态cell,你还得多拖出来一个UITableViewController 到storyboard上,假设为viewB
在viewA拖一个container view控件,按ctrl拖向viewB,此时会弹出一个菜单,选择embed ,即表示在viewA
中嵌入显示viewB

Alt text

题外话

做完后发现,仅仅为一个静态cell就费这么多功能并不值得,
因为你完全可以做同等数量的cell原型,在创建cell,写一些简单代码就能达到同样效果这里只为记录下一个解决办法

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值