iOS 5 Storyboard: How To use Segues, Scenes and Static Content UITableViews--Part II

Prototype Cells and Static Content
Other neat features of Storyboards are Prototype Cells and Static Content UITableViews. Lets first take a look at Prototype cells.

In the past we have to create our UITableViewCells in a nib and load them from the nib at runtime. This could result in lots of Cell nib files culturing up our project. Now we can create Prototype Cells directly inside our UITableViewController scene. In the following screenshot you can see our contacts UITableViewController scene where we have a custom prototype cell with a UIImageView and two labels.

To use your UITableViewCell prototypes you must provide them with a unique identifier that you set in Interface Builder. You can then dequeue the correct cell and set the content that it is to display in your cellForRowAtIndexPath method.

 static NSString *CellIdentifier = @"ContactsCell";
    ContactsTableViewCell *cell = (ContactsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    cell.contact = [contacts objectAtIndex:indexPath.row];

Note: That you can have as many different prototype cells as you wish the only requirement is that you set each one with a unique cell identifier.

It is also possible to create Segues between cells and ViewControllers to transition to a new scene when a cell is tapped. In the following screen shot you can see how to connect a cell to a UIViewController and by specifying Push as the transition mode we now have a detailed view pushed on whenever a cell is tapped.

As before we must specify an identifier for this Segue and pass data through to the view being shown via the prepareForSegue. This provides the newly presented view with the necessary data to be displayed.

Static Content UITableViews are an awesome new feature included in Storyboards. With Static UITableViews, cells can be designed inline without the need for an additional data source. Instead you can hook up UI elements that appear on different cells to IBOutlets in you UITableViewController class. In order to create a Static TableView layout you must change the Content type in the Attributes Inspector to Static as shown in the screen shot below.

I have also chosen to set the separator to none however you can leave the separator in if you wish to keep the UITableView look. Now that the view is laid out as we would like we can hook up the various UITextAreas and the UIImageView to your controller class. Finally I am going to finish with some additional Storyboard tips and resources.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值