iOS 5 Storyboard: How To use Segues, Scenes and Static Content UITableViews--Part II
2011-10-30 09:41
525 查看
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.
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.
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.
相关文章推荐
- iOS 5 Storyboard: How To use Segues, Scenes and Static Content UITableViews--Part II
- iOS 5 Storyboard: How To use Segues, Scenes and Static Content UITableViews--Part III
- iOS 5 Storyboard: How To use Segues, Scenes and Static Content UITableViews--Part I
- iOS 5 Storyboard: How To use Segues, Scenes and Static Content UITableViews--Part III
- iOS 5 Storyboard: How To use Segues, Scenes and Static Content UITableViews--Part I
- How to use virtual path providers to dynamically load and compile content from virtual paths in
- How to Use JSONKit for iOS and the Rotten Tomatoes API
- iOS中使用storyboard时出现警告Unsupported Configuration: Scene is unreachable due to lack of entry points and
- How to Configure iOS for iPhone and iPad to Use So
- How to create, develop, and distribute iOS Static Frameworks quickly and efficiently
- In an iOS 5 Storyboard, how do you push a new scene to the original view controller from a Popover?
- How to use virtual path providers to dynamically load and compile content from virtual paths in
- In an iOS 5 Storyboard, how do you push a new scene to the original view controller from a Popover?
- iOS开发UI-Quartz2D what about Quartz2D ?and how to use it ?
- iOS 5 Storyboard and UITableViews Tutorial
- How To: Compile and Use Tesseract (3.01) on iOS (SDK 5)
- [转]How to use IHttpContextAccessor in static class to set cookies
- How to use UTF-8_with_BOM, XML and Java together
- (位运算使用技巧)A summary: how to use bit manipulation to solve problems easily and efficiently
- Kernel Korner - Why and How to Use Netlink Socket