0

x 個のセクションと x 個のセクションあたりの行を使用して、UITableView を設定しようとしています。

ただし、ビューの上部に単一の行を追加したいのUITableViewですが、これをビューにハードコードする方法はありますか?

現在、NSdictionary に基づいて、セクションごとのセクション数と行数を返しています。

- (NSInteger)numberOfSectionsInTableView: (UITableView *)tableView
{
    // Return the number of sections.
    return [letterDictionary count];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // returns the number of rows per section based off each entry in letterDictionary   
    currentLetter = [sectionLetterArray objectAtIndex:section];
    return [[letterDictionary objectForKey:currentLetter] count];       
}
4

3 に答える 3

1

テーブルビューに「ヘッダー」を追加できます。

あなたのテーブルビュークラスで:

self.tableView.tableHeaderView = yourView;
于 2012-08-21T01:48:55.733 に答える
0

テーブルビュー セクションのヘッダーをカスタマイズしてみることができます...
たとえば、次のようなものを使用できます。

YourController.h
-(UIView *)headerView;

YourController.m
-(UIView *)headerView
{
    UIView *header = [[UIView alloc] initWithFrame:CGRectZero];
    // Place everything you want in your header
    // using [header addSubview:yourSubview];
    // Finally set header's frame and return it
    header.frame = CGRectMake(0.0, 0.0, 320.0, 44.0);
    return header;
}

// Use this to return header's height
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == yourSection)
    {
        return [self headerView].frame.size.height;
    }
    else
    {
        return [self sectionHeaderHeight];
    }
}

// Use this to return your view
-(UIView *)tableView:(UITableVIew *)tableVIew viewForHeaderInSection:(NSInteger)section
{
    if (section == yourSection)  // To show the header only on a specified section
    {
        return [self headerView];
    }
    else
    {
        return nil;
    }
}

気が変わって tableView の下をカスタマイズしたい場合は、ヘッダーとフッターを変更する同じ方法を使用できます。
最後に、これらのメソッドに関するドキュメントを
ご覧ください: - tableView:viewForHeaderInSection: - tableView:
heightForHeaderInSection:
- tableView:viewForFooterInSection:
- tableView:heightForFooterInSection:

これがあなたのニーズに合うことを願っています!

于 2012-08-20T22:42:16.023 に答える
0

テーブル内の UItable の上に行を追加することはできません。テキストの行だけが必要な場合は、必要に応じて UITextField、UILabel、または UITextView を使用し、UItable の上に好きな場所に配置してください。

私があなたを誤解していて、最初のセクションの最初の行として 1 つの行を追加したい場合は、次のようにする必要があります。

if (section == 0) {
  return [[letterDictionary objectForKey:currentLetter] count]+1;
} else
{
  return [[letterDictionary objectForKey:currentLetter] count];
}

また、indexpath の行を返すときに、同様の if ステートメントもあり、セクション == 0 と行 == 0 に必要なものを返すようにします。

ただし、テーブルビューを下にスクロールすると、この最初の行は確実にスクロールされます-言ったように、何が必要なのか正確にはわかりません。

于 2012-08-20T22:00:43.360 に答える