Frame of viewForHeaderInSection is always the same size

后端 未结 1 851
渐次进展
渐次进展 2021-02-07 05:08
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{

 if(section != 0) {

  UIView *view = [[[UIView alloc] initWithFrame:CGRectM         


        
相关标签:
1条回答
  • 2021-02-07 06:05

    You need to implement this delegate method

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

    In your case, you can simply return 30;.


    Also, you are leaking view!

    Your [view release] happens after the return. But as soon as the return happens the method execution is aborted and your release is never called.

    So you want this instead

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

    And get rid of the explicit release down below.

    0 讨论(0)
提交回复
热议问题