質問

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{

 if(section != 0) {

  UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 30)] autorelease];
  view.backgroundColor = [UIColor redColor];

  return view;

 } else {
  return tableView.tableHeaderView;
 }

}

これが私の実施viewForHeaderInSectionなフレームまでのものと同じ赤い枠がつきます。だけに見られる問題私のコードについて教えてください。

イメージ:

enter image description here

更新:

み、今の私にとって赤いブロックは高いが私の最初のtableHeaderは何かを隠します。最初にして実装されたtitleForHeaderInSection.と思ったん実施の高さtableHeader高さがるのだが仕事

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if(section == 1)
    return 30;
else
    return tableView.tableHeaderView.frame.size.height;
}
役に立ちましたか?

解決

を導入するために必要なこの委譲方法

    - (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section;

このケースではでき return 30;.


また、 お漏れ view!

[view release] が後に return.すが、 return う方法を実行が中断され、 release は決して呼び出されます。

だいこく

UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(10, 10, 100, 30)] autorelease];

とくに明示的に release しました。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top