0

このような tableView を作成したいと思います。(まあ、タイトルが違いますが;))

ここに画像の説明を入力

これまでにいくつかのアプリでそれらを見ましたが、それらを作成する方法がわかりません。色合い (ナビゲーション バーなど) とさまざまなアプリの外観が似ているため、それらはカスタム セルではなく、何か違うものだと思います。

もう 1 つ質問があります (カスタム セルの場合)。ストーリーボード テーブルビューでプロトタイプ セルのセルの高さ/背景を変更すると、追加の customcell クラスを作成するまでアプリに表示されません。私は何が欠けていますか?

if (indexPath.row == 0 || indexPath.row == 7)
{
    static NSString *CellIdentifier = @"TitleCell";
    UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    //heigh does not change -.-
    if (cell1 == nil){
        cell1 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    return cell1;
}
else {
static NSString *CellIdentifier = @"FirstCell";
UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell1 == nil){
    cell1 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell1.textLabel.text = [[articles objectAtIndex:indexPath.row]objectForKey:labelkey1];
4

1 に答える 1

3

それらはセクションヘッダーです。

次のメソッドを追加することで、セクションヘッダーを追加できます。

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{ 
     return @"My title";
}

複数のセクションを追加するには、次の方法から適切な値を渡す必要があります。

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 7;
}

各セクションの行数を渡します。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   return 2;
}

上記のコードから、それぞれ2行の7つのセクションが得られます。それに応じて、セクション、行、およびそれらのデータを処理する必要があります。

tableView:titleForHeaderInSection:

テーブルビューの指定されたセクションのヘッダーのタイトルをデータソースに要求します。-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)sectionパラメーター

tableView

The table-view object asking for the title.  section

An index number identifying a section of tableView .

戻り値

セクションヘッダーのタイトルとして使用する文字列。nilを返すと、セクションにタイトルがなくなります。討論

テーブルビューでは、セクションヘッダーのタイトルに固定フォントスタイルが使用されます。別のフォントスタイルが必要な場合は、代わりにデリゲートメソッドtableView:viewForHeaderInSection:でカスタムビュー(たとえば、UILabelオブジェクト)を返します。可用性

Available in iOS 2.0 and later.

関連項目

– tableView:titleForFooterInSection:

UITableView.hで宣言

参照 :

  1. UITableViewDataSource
  2. UITableView
于 2012-11-04T10:31:13.393 に答える