All the list-based data is displayed using TableView.
Preview
Pending additions
Raw Materials
- Nsfetchedresultscontroller
used to manipulate Nsfetchrequst, there are execution query, monitoring changes, data caching and other functions
- Nsfetchrequest
is used to specify which table to look for, how the result set is sorted
- Nssortdescriptor
Sort by must
- nspredicate
predicate, is actually query condition, optional
- UITableView
- uitableviewcontroller
Li class= "li3" > uitableview must specify DataSource, as long as there is no special requirement to use this viewcontroller directly, this class also declares the following two protocols
- uitableviewdatasource
as the name implies this protocol to implement data source related characteristics
- uitableviewdelegate
is responsible for TableView performance and action of the Protocol
Steps
- Storyboard Drag a table view controller, this table View controller comes with a TableView and a Tableviewcell
- Define a subclass of Uitableviewcontroller, and set the class of the Table View Controller to this subclass in Storyboard.
- Declares a nsfetchedresultscontroller private variable, initialized in Viewdidload.
- overriding two methods
- Numberofrowsinsection Returns the number of rows in the specified group, Nsfetchedresultscontroller knows the answer
- Cellforrowatindexpath the display value of the cell after getting the data through Nsfetchedresultscontroller, and then returns the cell
- You can smoke the test.
Code Snippets
Only Cellforrowatindexpath's regular writing is a bit special, here's just an example of it.
Override Func TableView (tableView: uitableview, Cellforrowatindexpath indexpath: nsindexpath)
- UITableViewCell {
var cellid = Identifier set for Tableviewcell in "cellid"//Property editor
var cell = TableView. Dequeuereusablecellwithidentifier(cellid) as UITableViewCell?
if cell = = nil{
Cell = UITableViewCell(Style:uitableviewcellstyle. Default, Reuseidentifier:cellid)
}
cell! . Textlabel?. Text="value taken out"
return cell!
}
links
- TableView Programming Guide
- Core Data Programming Guide
- Uitableviewdatasource Protocol Reference
- Uitableviewdelegate Protocol Reference
IOS Development Quick Guide: TableView and CoreData "Grass"