2012-03-16 3 views
4

У меня есть UITableView, к которому я добавляю tableFooterView, по какой-то причине tableFooterView не появляется?UITableView tableFooterView не отображается

Как добавить мой tableFooterView

добавляю tableFooterView в методе connectionDidFinishLoading после перезагрузки данных tableview.

Так что я делаю

[controls reloadData]; 

UIView *myFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)]; 
if(self.item.canRunOnDemand) 
{ 
    UIButton *buttonRunWorkflow = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [buttonRunWorkflow addTarget:self action:@selector(runWorkflow:) forControlEvents:UIControlEventTouchDown]; 
    [buttonRunWorkflow setTitle:@"Run Now" forState:UIControlStateNormal]; 
    buttonRunWorkflow.frame = CGRectMake(15, 5, 290, 44); 
    buttonRunWorkflow.backgroundColor = [UIColor clearColor]; 
    [buttonRunWorkflow setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
    [myFooterView addSubview:buttonRunWorkflow]; 
} 
if(item.canRunAlways) 
{ 
    UILabel *canRunAlwaysLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 46, 100, 44)]; 
    canRunAlwaysLabel.backgroundColor = [UIColor clearColor]; 
    canRunAlwaysLabel.text = @"Run Always:"; 
    UISwitch *canRunAlways = [[UISwitch alloc] initWithFrame:CGRectMake(115, 56, 100, 44)]; 
    [canRunAlways addTarget:self action:@selector(canRunAlwaysChanged:) forControlEvents:UIControlEventValueChanged]; 
    [myFooterView addSubview:canRunAlways]; 
    [myFooterView addSubview:canRunAlwaysLabel]; 
    [canRunAlwaysLabel release]; 
    [canRunAlways release]; 
} 

[myFooterView release]; 

[controls.tableFooterView addSubview:myFooterView]; 

высота вид Footer

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
{ 
    return 100; 
} 

Я также попытался это:

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section 
{ 
    if(section == [[fields objectAtIndex:section] count] - 1) 
    { 
     return 100; 
    } 
    else { 
     return 0; 
    } 
} 
-(UIView*) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 
    if(section == [[fields objectAtIndex:section] count] - 1) 
    { 
     UIView *myFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 80)]; 
     if(self.item.canRunOnDemand) 
     { 
      UIButton *buttonRunWorkflow = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
      [buttonRunWorkflow addTarget:self action:@selector(runWorkflow:) forControlEvents:UIControlEventTouchDown]; 
      [buttonRunWorkflow setTitle:@"Run Now" forState:UIControlStateNormal]; 
      buttonRunWorkflow.frame = CGRectMake(15, 5, 290, 44); 
      buttonRunWorkflow.backgroundColor = [UIColor clearColor]; 
      [buttonRunWorkflow setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 
      [myFooterView addSubview:buttonRunWorkflow]; 
     } 
     if(item.canRunAlways) 
     { 
      UILabel *canRunAlwaysLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 46, 100, 44)]; 
      canRunAlwaysLabel.backgroundColor = [UIColor clearColor]; 
      canRunAlwaysLabel.text = @"Run Always:"; 
      UISwitch *canRunAlways = [[UISwitch alloc] initWithFrame:CGRectMake(115, 56, 100, 44)]; 
      [canRunAlways addTarget:self action:@selector(canRunAlwaysChanged:) forControlEvents:UIControlEventValueChanged]; 
      [myFooterView addSubview:canRunAlways]; 
      [myFooterView addSubview:canRunAlwaysLabel]; 
      [canRunAlwaysLabel release]; 
      [canRunAlways release]; 
     } 
     return myFooterView; 
    } 
    else { 
     return nil; 
    } 
} 
+0

Вы уверены, что имеете правильную высоту для нижнего колонтитула? heightForFooterInSection ..... – janusbalatbat

+0

Да, я уверен, я установил его следующим образом: – Armand

+0

см. это: http://stackoverflow.com/questions/9021315/grouped-uitableview-subviews/9021898#9021898 Я также добавил пример проекта – vikingosegundo

ответ

7

Глядя на заголовочный файл UITableView.h мы видим декларацию собственности tableFooterView так:

@property(nonatomic,retain) UIView *tableFooterView; // accessory view below content. default is nil. not to be confused with section footer 

так по умолчанию property является nil. Вот почему вы не можете добавить еще UIView в ноль UIView. Вы должны сделать что-то вроде этого:

controls.tableFooterView = myFooterView; 
+0

Отличный ответ, кажется, работает – Armand

-3

Вы пытаетесь добавить вид колонтитула в виде таблицы? Если вы пытаетесь за что Реализуйте вид колонтитула в этом методе

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 

Это может помогает you.thanks !!

+0

Но что происходит, когда таблица пуста? – Armand

+0

Вы вводите в заблуждение «нижний колонтитул раздела» с «нижними колонтитулами стола» здесь. ОП просил последнего. – Regexident

+1

Это неверно, нижние колонтитулы надписятся над таблицей. – Zorayr

Смежные вопросы