IOS_UI_UITableView 应用

#import <UIKit/UIKit.h>


@interface AppDelegate : UIResponder <UIApplicationDelegate>


@property (strong, nonatomic) UIWindow *window;



@end

#import "AppDelegate.h"

#import "MainViewController.h"

@interface AppDelegate ()


@end


@implementation AppDelegate

- (void)dealloc

{

    [_window release];

    [super dealloc];

}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    [_window release];

    

    MainViewController *mainVC = [[MainViewController alloc]init];

    self.window.rootViewController = mainVC;

    [mainVC release];

    return YES;

}


#import <UIKit/UIKit.h>


@interface MainViewController : UIViewController


@end


#import "MainViewController.h"


@interface MainViewController ()<UITableViewDelegate,UITableViewDataSource>

//协议1.1.创建一个数组的属性,用于装tableView的数据.(保证里面的每一条数据的结构都是相同的)

@property (nonatomic,retain)NSMutableArray *arr;


@end


@implementation MainViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    //协议1  2. 初始化数组

    self.arr = [NSMutableArray arrayWithObjects:@"张洋", @"邱文辉", @"席彦贵", @"张建勋", @"杨乾坤", @"赵鑫", @"杨宇航", @"宿志勇", @"姜洪志", @"逄仁秀", @"耿荣林", @"王利玮", @"单剑秋", @"王宇", @"李思洋", @"符立", @"张旭欣", @"杨钧焱", @"焦鹏", @"张伟", @"林楠", @"齐玉婷", @"杨旭", @"韩松", @"李剑锋", @"石广旭", @"金运通", @"王铁臣", @"于海龙", @"赵斯林", @"宣奇才", @"赵翌然", @"杨斌", @"范有政", @"赵正", @"潘振", @"乔彦", @"吕品", @"庞泽人", @"陈宁", @"刘赞莹", @"王守一", @"孙雪丽", @"刘哲", @"冯科远", nil];

    

       UITableView *table = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];

    [self.view addSubview:table];

    [table release];

    table.dataSource = self;

    table.delegate = self;

    // 刷新tableView

    [table reloadData];

    

    //读取app内文件

    NSString *path = [[NSBundle mainBundle] pathForResource:@"Property List" ofType:@"plist"];

    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfFile:path];

    NSLog(@"%@",dic);

    

    

    

    

}

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

{

    //协议1 3.根据数组的个数返回

    return self.arr.count;

}

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

{

    static NSString *reuseID = @"reuse";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID];

    if (cell == nil) {

        cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseID] autorelease];

    }

//    cell.textLabel.text = @"hi";

//    cell.detailTextLabel.text = @"nihao";

    //根据下标从数组里取东西

    NSString *name = [self.arr objectAtIndex:indexPath.row];

    cell.detailTextLabel.text = name;

    //    cell.textLabel.text = name;

    cell.textLabel.text = [NSString stringWithFormat:@"section:%ld,row:%ld",indexPath.section,indexPath.row];

    return cell;

}

//当点击某个cell的时候,执行这个协议方法

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

{

    NSLog(@"点击cell : %@",[self.arr objectAtIndex:indexPath.row]);

}

//分区数

- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView

{

    return 3;

}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

    //给分区的顶部加字符串

    return [NSString stringWithFormat:@"Section:%ld",section];


}

//分区的顶部高度

- (CGFloat )tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    return 100;

}

//每一行高度

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (indexPath.section == 1 && indexPath.row == 1) {

        return 200;

    }

    return 80;

}



- (void)dealloc

{

    [_arr release];

    [super dealloc];

}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值