IOS-read plist files

Source: Internet
Author: User

IOS-read plist files

// UI-city list

//

// Created by jzq_macon 15/7/30.

// Copyright (c) jzq_mac. All rights reserved.

//

 

# Import ViewController. h

# Import DetailViewController. h

@ Interface ViewController ()

{

NSArray * allCitys;

UITableView * myTableView;

}

@ End

 

@ Implementation ViewController

 

-(Void) viewDidLoad {

[Super viewDidLoad];

[Self loadData];

[Self creatTableView];

 

 

 

}

 

 

 

# Pragma ---------------------- obtain data in plist ----------------------

 

-(Void) loadData {

NSString * path = [[NSBundle mainBundle] pathForResource: @ citys. plist ofType: nil];

AllCitys = [NSArray arrayWithContentsOfFile: path];

NSLog (% @, allCitys );

 

}

 

 

# Pragma -------------------- initialize TableView ----------------------

 

-(Void) creatTableView

{

MyTableView = [[UITableView alloc] initWithFrame: CGRectMake (0, 20, CGRectGetWidth (self. view. frame), CGRectGetHeight (self. view. frame)-20) style: UITableViewStylePlain];

MyTableView. delegate = self;

MyTableView. dataSource = self;

[Self. view addSubview: myTableView];

}

 

 

 

# Pragma ---------------------- UITableViewDelegate ---------------------

-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section

{

Return allCitys. count;

}

 

 

# Pragma ---------------------- UITableViewDataSource ---------------------

-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath

{

NSString * cellID = @ cityCell; // unique cell identifier

// TableView: Check whether there is a cell called cellID (full screen)

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: cellID];

// Initialize the cell if no result is found.

If (! Cell ){

Cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: cellID];

 

}

 

Cell. textLabel. text = allCitys [indexPath. row] [@ State];

Return cell;

 

}

 

 

 

-(Void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath

{

DetailViewController * detail = [[DetailViewController alloc] init];

 

// Mode switch ViewController; used to temporarily switch to another ViewController and put the ViewController to be displayed on the top of the presentedViewController

// Disable dismissViewControllerAnimated when you no longer need to put the ViewController on the top.

Detail. modalTransitionStyle = UIModalTransitionStylePartialCurl;

[Self presentViewController: detail animated: YES completion: nil];

 

}

 

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.