忍者ブログ
2024 / 09
≪ 2024 / 081 2 3 4 5 6 78 9 10 11 12 13 1415 16 17 18 19 20 2122 23 24 25 26 27 2829 30 2024 / 10 ≫

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。



section を増やしてみました。

#pragma mark Table view methods
// seciotn の数を 3 にします。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

// Customize the number of rows in the table view.
// Table View の行の数をカスタマイズ と 各 section ごとのCell の数を設定。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch( section ) {
       case 0: return 4;
       case 1: return 3;
       case 2: return 1;
   default: return 0;
}
}
//デフォルトでは存在しないので、以下を丸ごと追加
//section のデータをセットしてます。
- (NSString *) tableView:(UITableView *) tableView titleForHeaderInSection:(NSInteger) section {

    switch( section ) {
       case 0: return @"果物";
       case 1: return @"野菜";
       case 2: return @"飲み物";
   }
   return nil;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

// Set up the cell...
// section ごとの Cell の中身をセット。
    if( indexPath.section == 0 ) {
          if( indexPath.row == 0 ) {
                cell.text = @"すいか";
          }else if( indexPath.row == 1 ) {
                cell.text = @"メロン";
          }else if( indexPath.row == 2 ) {
                cell.text = @"柿";
          }else if( indexPath.row == 3 ) {
                    cell.text = @"いちご";
          } 
          }else
          if( indexPath.section == 1 ) {
                    if( indexPath.row == 0 ) {
                              cell.text = @"白菜";
                    }else if( indexPath.row == 1 ) {
                              cell.text = @"キャベツ";
                    }else if( indexPath.row == 2 ) {
                              cell.text = @"ねぎ";
                    }
                    } else
                              cell.text = @"ビール";
          return cell;
}

実行〜
ebda72e6.jpg
section の分類項目が入った〜(^^)v
section ごとのデータも入ってるね。

くだらないことだけど、思った通り動くと嬉しいね!













ここまで覚えると、とりあえずテーブルができるね。


PR


この記事へコメントする








絵文字:
Vodafone絵文字 i-mode絵文字 Ezweb絵文字








08 2024/09 10
S M T W T F S
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
HN:
cow

自己紹介:
iPhone購入がきっかけでiPhoneアプリの制作にチャレンジ!