【问题标题】:Add UITableView Inside FooterView Of another Table (didSelectRowAtIndexPath not getting called On the UITableView added)在另一个表的 FooterView 中添加 UITableView(在添加的 UITableView 上未调用 didSelectRowAtIndexPath)
【发布时间】:2015-11-22 19:26:26
【问题描述】:
  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

当我选择 UITableView 中的单元格时,上面的函数没有被调用,该单元格已插入到另一个 UITableView 的 footerView

我在下面的函数中添加了 UITableView,我可以看到我插入的所有项目

但我无法点击单元格。

我还插入了一些 UIButton 来检查点击是否正常工作,工作正常

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

提前致谢。

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

    if(tableView==_ordersListTable)
    {
//creating view to pass to footerview
    UIView *footerView;
        footerView.userInteractionEnabled=true;

    if(footerView == nil) {
        //allocate the view if it doesn't exist yet
        footerView  = [[UIView alloc] init];
}
       //initializing table
                _paymentInfoTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 40, 320, 80)];


      _paymentInfoTable.backgroundColor = [UIColor whiteColor];
        _paymentInfoTable.delegate = self;
        _paymentInfoTable.dataSource = self;
        //_paymentInfoTable.separatorStyle = UITableViewCellSeparatorStyleNone;

        _paymentInfoTable.separatorInset = UIEdgeInsetsMake(0, 110, 0, 180);

        [footerView addSubview:_paymentInfoTable];
    }
    //return the view for the footer
        return footerView;
} else
    {
        return 0;
    }
}

【问题讨论】:

  • 您忘记设置委托了吗?
  • 委托和数据源都设置好了..
  • 你能再贴一些代码吗,这只是猜测:-)

标签: ios objective-c iphone uitableview


【解决方案1】:

因为你有两个 UITableView 需要控制,所以两个 UITableView 的代理都必须正确设置。你设置了这些代表吗?

通过检查委托方法中的 UITableView,您可以控制两个 UITableView:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView == self.tableView1) {
        // Do your thing with the first UITableView
    }
    else {
        // Do your thing with the other UITableView
    }
}

【讨论】:

  • 我已经这样做了......但是这个函数也没有被调用......单元格甚至没有改变选择的颜色......selectionstyle是默认的
  • 确保你的 superviews 上没有任何 UIGestures,否则 UITableView 不会注册任何触摸。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-16
  • 2013-12-07
相关资源
最近更新 更多