UITableView tableFooterView не появляется - PullRequest
5 голосов
/ 16 марта 2012

У меня есть UITableView, к которому я добавляю tableFooterView, по какой-то причине 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];

Высота вида нижнего колонтитула

- (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;
    }
}

Ответы [ 2 ]

7 голосов
/ 16 марта 2012

Глядя на заголовочный файл 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 к nil UIView. Вы должны сделать что-то вроде этого:

controls.tableFooterView = myFooterView;
0 голосов
/ 16 марта 2012

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

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

Это может вам помочь. Спасибо !!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...