你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS開發學習之#表視圖#(4)填充Grouped風格的分組表

iOS開發學習之#表視圖#(4)填充Grouped風格的分組表

編輯:IOS開發綜合

直接上代買吧:

@implementation ViewController

- (void)viewDidLoad {
    a = [NSArray arrayWithObjects:@"ant",@"alpaca",@"albatross", nil];
    b = [NSArray arrayWithObjects:@"badger",@"bat",@"bear", nil];
    c = [NSArray arrayWithObjects:@"cat",@"calf",@"cattle", nil];
    d = [NSArray arrayWithObjects:@"A",@"B",@"C", nil];
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}
//設置表視圖的行數
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }
    if (indexPath.section == 0) {
        cell.textLabel.text = [a objectAtIndex:indexPath.row];
    }
    if (indexPath.section == 1) {
        cell.textLabel.text = [b objectAtIndex:indexPath.row];
    }
    if (indexPath.section == 2) {
        cell.textLabel.text = [c objectAtIndex:indexPath.row];
    }
    return cell;
}
//設置表視圖的節數
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [d count];
}
//獲取節的名稱
- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return [d objectAtIndex:section];
}


  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved