【问题标题】:UIButton In Table Footer Unresponsive表格页脚中的 UIButton 无响应
【发布时间】:2011-07-03 06:09:02
【问题描述】:

对于自定义表格页脚,我使用以下代码

- (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 没有被识别的任何想法?

【问题讨论】:

    标签: iphone xcode uitableview uibutton


    【解决方案1】:

    哇!!!

    在这段代码的正下方,我有

    // 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 就好了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-09
      • 1970-01-01
      • 2018-04-26
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多