IOS project development practice-learn to use the TableView list control (4) plist reading and Section display

Source: Internet
Author: User

IOS project development practice-learn to use the TableView list control (4) plist reading and Section display

The text will store the data in the plist file and then read it in the program. The Section is displayed in the TableView control according to different categories. For other implementations of TableView, see iOS project development practices-learn to use TableView list controls (1), iOS project development practices-learn to use TableView list controls (2) iOS project development practice-learn to use the TableView list control (3) understand Section.

(1) create a Property List file, which is the plist file. I named data. plist. The input content is as follows:

.

 

(2) The implementation in the Code is as follows:

 

import UIKitclass ViewController: UIViewController ,UITableViewDataSource{  var data:NSDictionary!    override func viewDidLoad() {    super.viewDidLoad()        data = NSDictionary(contentsOfURL: NSBundle.mainBundle().URLForResource(data, withExtension: plist)!)          }  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {    var cell = tableView.dequeueReusableCellWithIdentifier(cell) as! UITableViewCell        var title = cell.viewWithTag(101) as! UILabel    title.text = (data.allValues[indexPath.section] as! NSArray).objectAtIndex(indexPath.row) as? String        return cell      }    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {        return (data.allValues[section] as! NSArray).count  }    func numberOfSectionsInTableView(tableView: UITableView) -> Int {        return data.count  }    func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {        return data.allKeys[section] as? String  }  }

(3) The final implementation result is as follows:

 

 

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.