วันอังคารที่ 5 มีนาคม พ.ศ. 2556

iOS UITableView Tutorial

.h

@property (retain, nonatomic) NSArray *tableData;

.m
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Initialize table data
    self.tableData = [NSArray arrayWithObjects:@"Egg Benedict"@"Mushroom Risotto"@"Full Breakfast"@"Hamburger"@"Ham and Egg Sandwich"@"Creme Brelee"@"White Chocolate Donut"@"Starbucks Coffee"@"Vegetable Curry"@"Instant Noodle with Egg"@"Noodle with BBQ Pork"@"Japanese Noodle with Pork"@"Green Tea"@"Thai Shrimp Cake"@"Angry Birds Cake"@"Ham and Cheese Panini"nil];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.tableData count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [self.tableData objectAtIndex:indexPath.row];
    return cell;
}

ไม่มีความคิดเห็น:

แสดงความคิดเห็น