iOS.UIKit.13.UITableView -- Simple

來源:互聯網
上載者:User

標籤: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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.