这几天都有一些任务要跟, 把ios的学习拉后, 看看要抓紧咯, 看看轮到的学习的是UITableView。
BIDViewController.h
#import <UIKit/UIKit.h>
@interface BIDViewController : UIViewController
<UITableViewDataSource, UITableViewDelegate>
@property (copy, nonatomic) NSArray *computers;
@end
BIDViewController.m
#import
"
BIDViewController.h
"
#import
"
BIDNameAndColorCell.h
"
@implementation
BIDViewController
static NSString *CellTableIdentifier = @"CellTableIdentifier"; // 重用标记
- (void)viewDidLoad
{
[super viewDidLoad];
self.computers = @[
@{@"Name" : @"MacBook", @"Color" : @"White"},
@{@"Name" : @"MacBook Pro", @"Color" : @"Silver"},
@{@"Name" : @"iMac", @"Color" : @"Silver"},
@{@"Name" : @"Mac Mini", @"Color" : @"Silver"},
@{@"Name" : @"Mac Pro", @"Color" : @"Silver"}]; // 为NSArray赋数值
UITableView *tableView = (id)[self.view viewWithTag:1]; // 这个view是controller管理的, viewWithTag是根据设定的tab
tableView.rowHeight = 65; // 设置每行的高度
UINib *nib = [UINib nibWithNibName:@"BIDNameAndColorCell"
bundle:nil];
[tableView registerNib:nib
forCellReuseIdentifier:CellTableIdentifier];
}
#pragma mark -
#pragma mark Table Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
return [self.computers count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
BIDNameAndColorCell *cell = [tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
NSDictionary *rowData = self.computers[indexPath.row];
cell.name = rowData[@"Name"];
cell.color = rowData[@"Color"];
return cell;
}
@end
原文:http://www.cnblogs.com/lee0oo0/p/3761337.html
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!