標籤:c style class blog code java
這幾天都有一些任務要跟, 把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 BIDViewControllerstatic 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