码迷,mamicode.com
首页 > 移动开发 > 详细

iOS.UIKit.13.UITableView -- Simple

时间:2014-06-06 16:48:16      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:c   style   class   blog   code   java   

 

1、案例介绍:最简单的表视图,如图01

bubuko.com,布布扣图01

2、team.plist

bubuko.com,布布扣
<?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>
bubuko.com,布布扣

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

bubuko.com,布布扣图02

5、.h

bubuko.com,布布扣
#import <UIKit/UIKit.h>

@interface CQ21ViewController : UITableViewController

@property (nonatomic, strong) NSArray *listTeams;

@end
bubuko.com,布布扣

6、.m

bubuko.com,布布扣
#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
bubuko.com,布布扣

 

iOS.UIKit.13.UITableView -- Simple,布布扣,bubuko.com

iOS.UIKit.13.UITableView -- Simple

标签:c   style   class   blog   code   java   

原文地址:http://www.cnblogs.com/cqchen/p/3766395.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!