#import "ImageViewController.h"
#import "Data.h"
@interface ImageViewController () <UITableViewDataSource>
@property (nonatomic, copy )NSArray *imageArray, *labelArray;
@property (nonatomic, copy)NSArray *dataArray;
@end
static NSString *identifier = @"abc";
@implementation ImageViewController
- (void)dealloc
{
[_dataArray release];
[_labelArray release];
[_imageArray release];
[super dealloc];
}
- (void)viewDidLoad {
[super viewDidLoad];
UITableView *tabView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
[self.view addSubview:tabView];
tabView.dataSource = self;
[tabView registerClass:[UITableViewCell class] forCellReuseIdentifier: identifier];
tabView.rowHeight = 100;
[tabView release];
self.imageArray = [[[NSArray alloc] initWithObjects:@"picture1.jpg",@"picture2.jpg",@"picture3.jpg",@"picture4.jpg",@"picture5.jpg",nil] autorelease];
self.labelArray = @[@"你好, 我叫小芳", @"good morning", @"你真的好棒呀", @"yes, yes, you are right", @"好好学习. 天天向上"];
Data *data1 = [Data dataWithLabel:@"你好, 我叫小芳" image:@"picture1.jpg"];
Data *data2 = [Data dataWithLabel:@"good morning" image:@"picture2.jpg"];
Data *data3 = [Data dataWithLabel:@"你真的好棒呀" image:@"picture3.jpg"];
Data *data4 = [Data dataWithLabel:@"yes, yes, you are right" image:@"picture4.jpg"];
Data *data5 = [Data dataWithLabel:@"好好学习. 天天向上" image:@"picture5.jpg"];
self.dataArray = @[data1, data2, data3, data4, data5];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
self.dataArray = [NSArray arrayWithContentsOfFile:path];
NSLog(@"%@", self.dataArray);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier forIndexPath:indexPath];
NSDictionary *dic = self.dataArray[indexPath.row];
cell.imageView.image = [UIImage imageNamed:dic[@"image"]];
cell.imageView.layer.cornerRadius = 50;
cell.imageView.clipsToBounds = YES;
cell.textLabel.text = dic[@"label"];
cell.textLabel.numberOfLines = 0;
return cell;
}
@end