UIButton In Table Footer не отвечает - PullRequest
4 голосов
/ 24 февраля 2011

Для пользовательских нижних колонтитулов я использую следующий код

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    if(editmode) {
    if(footerView == nil) {
        //allocate the view if it doesn't exist yet
        footerView  = [[UIView alloc] init];

        //we would like to show a gloosy red button, so get the image first
        UIImage *image = [[UIImage imageNamed:@"button_green.png"] stretchableImageWithLeftCapWidth:8 topCapHeight:8];

        //create the button
        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [button setBackgroundImage:image forState:UIControlStateNormal];

        //the button should be as big as a table view cell
        [button setFrame:CGRectMake(10, 3, 300, 44)];

        //set title, font size and font color
        [button setTitle:@"Photo" forState:UIControlStateNormal];
        [button.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

        //set action of the button
        [button addTarget:self action:@selector(selectExistingPicture) forControlEvents:UIControlEventTouchUpInside];

        //add the button to the view
        [footerView addSubview:button];
        UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        image = [[UIImage imageNamed:@"button_grey_dark.png"] stretchableImageWithLeftCapWidth:8 topCapHeight:8];
        [button2 setBackgroundImage:image forState:UIControlStateNormal];

        //the button should be as big as a table view cell
        [button2 setFrame:CGRectMake(10, 50, 300, 44)];

        //set title, font size and font color
        [button2 setTitle:@"Note" forState:UIControlStateNormal];
        [button2.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
        [button2 setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

        //set action of the button
        [button2 addTarget:self action:@selector(mkFolder) forControlEvents:UIControlEventTouchUpInside];

        //add the button to the view
        [footerView addSubview:button2];

        //      [button setupAsRedButton];
    }

    //return the view for the footer
    return footerView;
    } 
    return nil;
}

При использовании этой кнопки первая кнопка отлично реагирует, однако вторая не регистрирует никаких событий. Даже если функция не существует, ошибка нулевой функции не генерируется. Любые идеи о том, почему UITouchUpInside не распознается?

1 Ответ

9 голосов
/ 24 февраля 2011

Doh !!!

Прямо под этим кодом у меня было

// specify the height of your footer section
- (CGFloat)tableView:(UITableView *)tableView
heightForFooterInSection:(NSInteger)section {
    //differ between your sections or if you
    //have only on section return a static value
    return 50;
}

, которое устанавливало UIView для игнорирования всего, что меньше 50 пикселей.Изменил это на 100, и я был хорош.

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