IOS Development Quick Guide: TableView and CoreData "Grass"

Source: Internet
Author: User

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
    1. Storyboard Drag a table view controller, this table View controller comes with a TableView and a Tableviewcell
    2. Define a subclass of Uitableviewcontroller, and set the class of the Table View Controller to this subclass in Storyboard.
    3. Declares a nsfetchedresultscontroller private variable, initialized in Viewdidload.
    4. overriding two methods
    5. Numberofrowsinsection Returns the number of rows in the specified group, Nsfetchedresultscontroller knows the answer
    6. Cellforrowatindexpath the display value of the cell after getting the data through Nsfetchedresultscontroller, and then returns the cell
    7. 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"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.