@interface ViewController () <UITableViewDataSource,UITableViewDelegate>
@property NSMutableArray *items;
@end
@implementation ViewController
@synthesize items;
- (void)viewDidLoad
{
[super viewDidLoad];
items = (NSMutableArray *)@[@"a",@"b",@"c"];
UITableView *myTableView = [[UITableView alloc]
initWithFrame:CGRectMake(0, 30, 320, 460)];
[self.view addSubview:myTableView];
myTableView.dataSource = self;
}
//テーブルの行数を返す
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:
(NSInteger)section {
return items.count;
}
//テーブルの中のセルの情報を返す
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cid = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cid];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cid];
}
cell.textLabel.text = items[indexPath.row];
return cell;
}