標籤:c style class blog code java
1、案例介紹:最簡單的表視圖,01
圖01
2、team.plist
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"> <array> <dict> <key>name</key> <string>A1-南非</string> <key>image</key> <string>SouthAfrica</string> </dict> <dict> <key>name</key> <string>A2-墨西哥</string> <key>image</key> <string>Mexico</string> </dict> <dict> <key>name</key> <string>B1-阿根廷</string> <key>image</key> <string>Argentina</string> </dict> <dict> <key>name</key> <string>B2-尼日利亞</string> <key>image</key> <string>Nigeria</string> </dict> <dict> <key>name</key> <string>C1-英格蘭</string> <key>image</key> <string>England</string> </dict> <dict> <key>name</key> <string>C2-美國</string> <key>image</key> <string>USA</string> </dict> <dict> <key>name</key> <string>D1-德國</string> <key>image</key> <string>Germany</string> </dict> <dict> <key>name</key> <string>D2-澳大利亞</string> <key>image</key> <string>Australia</string> </dict> <dict> <key>name</key> <string>E1-荷蘭</string> <key>image</key> <string>Holland</string> </dict> <dict> <key>name</key> <string>E2-丹麥</string> <key>image</key> <string>Denmark</string> </dict> <dict> <key>name</key> <string>G1-巴西</string> <key>image</key> <string>Brazil</string> </dict> <dict> <key>name</key> <string>G2-朝鮮</string> <key>image</key> <string>NorthKorea</string> </dict> <dict> <key>name</key> <string>H1-西班牙</string> <key>image</key> <string>Spain</string> </dict> <dict> <key>name</key> <string>H2-瑞士</string> <key>image</key> <string>Switzerland</string> </dict> </array></plist>
3、圖片
Algeria.png、Argentina.png、Australia.png、Brazil.png、Cameroon.png、
Chile.png、CoteDIvoire.png、Denmark.png、England.png、France.png、
Germany.png、Ghana.png、Greece.png、Holland.png、Honduras.png、
Italy.png、Japan.png、Mexico.png、NewZealand.png、Nigeria.png、
NorthKorea.png、Paraguay.png、Portugal.png、Serbia.png、Slovakia.png、
Slovenia.png、SouthAfrica.png、SouthKorea.png、Spain.png、Switzerland.png、
Uruguay.png、USA.png
4、Main.storyboard,02
圖02
5、.h
#import <UIKit/UIKit.h>@interface CQ21ViewController : UITableViewController@property (nonatomic, strong) NSArray *listTeams;@end
6、.m
#import "CQ21ViewController.h"@interface CQ21ViewController ()@end@implementation CQ21ViewController- (void)viewDidLoad{ [super viewDidLoad]; // 載入球隊資料 NSBundle *bundle = [NSBundle mainBundle]; NSString *plistPath = [bundle pathForResource:@"team" ofType:@"plist"]; self.listTeams = [[NSArray alloc] initWithContentsOfFile:plistPath];}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning];}#pragma mark UITableViewDataSource協議- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ // 返回表格的行數 return self.listTeams.count;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ // 1、載入cell static NSString *CellIdentifier = @"CellIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // 2、設定cell的textLabel NSUInteger row = [indexPath row]; NSDictionary *rowDict = [self.listTeams objectAtIndex:row]; cell.textLabel.text = [rowDict objectForKey:@"name"]; // 3、設定cell的圖片 NSString *imagePath = [rowDict objectForKey:@"image"]; imagePath = [imagePath stringByAppendingString:@".png"]; cell.imageView.image = [UIImage imageNamed:imagePath]; // 4、設定cell擴充視圖為擴充指標 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell;}@end