iphone - UITableView footerView 带按钮,按钮不起作用

标签 iphone uitableview footer

我正在尝试为我的 UITableView footerView 创建一个自定义 View ,其中有一个按钮。我可以在那里看到它,但是当我触摸它时,什么也没有发生...你能看到这里出了什么问题吗:

- (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.");
}

最佳答案

您没有设置 footerView 的框架。将 footerView 的框架设置为至少与按钮一样高,否则触摸不会传递到按钮。

关于iphone - UITableView footerView 带按钮,按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3989740/

相关文章:

iphone - 从 AppDelegate 调用 presentModalViewController 不起作用

ios - 快速将任何对象转换为 bool 值?

iphone - 我如何在带有搜索结果 Controller 的 Storyboard 中使用原型(prototype)单元

html - 页脚未显示在网页上,但我可以在页面加载时看到它

android - 如何在 android 中使用 ScrollView 固定页脚?

html - 页脚不粘在底部

iphone - 使用 xcode 和 tablecells 登录表单

iphone - 如何从 Objective-C 中的 View Controller 访问主窗口?

ios - 检测底层 UITableViewCell 上的触摸并点击 UITextview 的属性文本

ios - 单击时使表行不突出显示