UITableView нижний колонтитул с кнопкой, кнопка не работает - PullRequest
24 голосов
/ 21 октября 2010

Я пытаюсь создать пользовательское представление для моего UITableView footerView, в котором есть кнопка. Я вижу это там, но когда я касаюсь этого, ничего не происходит ... вы видите, что здесь не так:

- (void)viewDidLoad {
    [super viewDidLoad];

    if(self.tableView.tableFooterView == nil) {
        //allocate the view if it doesn't exist yet
        UIView *footerView  = [[UIView alloc] init];

        //create the button
        UIButton *addNewBtn = [UIButton buttonWithType:UIButtonTypeCustom];     
        //the button should be as big as a table view cell
        [addNewBtn setFrame:CGRectMake(0, 0, 320, [AddMerchantTVC cellHeight])];

        //set title, font size and font color
        [addNewBtn setTitle:@"Add New" forState:UIControlStateNormal];
        [addNewBtn.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
        [addNewBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [addNewBtn addTarget:self action:@selector(addNew:) forControlEvents:UIControlEventTouchUpInside];

        UIImageView *cellGradient = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellGradient.png"]];
        cellGradient.frame = CGRectMake(0, 54, 320, 16);
        [footerView addSubview:cellGradient];

        //add the button to the view
        [footerView addSubview:addNewBtn];
        footerView.userInteractionEnabled = YES;
        self.tableView.tableFooterView = footerView;
        self.tableView.tableFooterView.userInteractionEnabled = YES;

        [footerView release];
        [cellGradient release];
}

- (void)addNew:(id)sender {
    // This is never called
    NSLog(@"Touched.");
}

Ответы [ 5 ]

38 голосов
/ 21 октября 2010

Вы не устанавливаете рамку footerView.Установите рамку нижнего колонтитула как минимум так же высоко, как кнопка, иначе касания не будут переданы кнопке.

7 голосов
/ 15 сентября 2012
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 50.0f;
}

Поместите этот метод в свой класс, ваша проблема решится .....

1 голос
/ 07 января 2014

это сработало для меня, я просто добавляю

footerView.frame =CGRectMake(0, 300, 100, 100);
0 голосов
/ 21 октября 2011

Вам нужно установить свойство tableView sectionFooterHeight до вызова viewForFooterInSection (не может сделать это внутри метода viewForFooterInSection).

0 голосов
/ 21 октября 2010

Создайте подкласс UIView и включите эти методы:

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    return [super hitTest:point withEvent:event];
}

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
    return [super pointInside:point withEvent:event];
}
...