#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];
}