iOS 点击Tableview中的Button来确定Section和Row

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UIButton *deleBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - WIDTH(76), 25, WIDTH(76), HEIGHT(36))];
    [deleBtn setBackgroundImage:[UIImage imageNamed:@"dierbu-shanchu.png"]
                       forState:UIControlStateNormal];
    //添加响应事件.
    [deleBtn addTarget:self action:@selector(deletBtnTap: event:) forControlEvents:UIControlEventTouchUpInside];
- }

// 点击方法

- (void)deletBtnTap:(UIButton *)sender event:(id)event{

    NSSet *touches=[event allTouches];

    UITouch *touch=[touches anyObject];
    CGPoint cureentTouchPosition=[touch locationInView:self.tableView];
    //得到indexPath
    NSIndexPath *indexPath=[self.tableView indexPathForRowAtPoint:cureentTouchPosition];
    NSLog(@"section----%ld,----row---%ld",indexPath.section,indexPath.row);

// 接下来可以根据section&Row来进行操作了

    switch(section){
        case row:
        {
            break;
        }
        default:
            break;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要获取在QTableView单选按钮所在的行号,可以使用信号和槽函数来实现。当单选按钮被选时,将发出信号,并将单元格的行号和列号作为参数传递给槽函数。您可以使用QItemSelectionModel类来获取当前选定的单元格。 以下是一个示例代码: ```cpp QTableView *tableView = new QTableView(this); tableView->setModel(model); // 创建一个QItemSelectionModel对象 QItemSelectionModel *selectionModel = tableView->selectionModel(); // 连接单元格选信号和槽函数 connect(selectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(onSelectionChanged(const QItemSelection &, const QItemSelection &))); void MyClass::onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected) { QModelIndexList indexList = selected.indexes(); // 遍历选的单元格,获取行号 for (int i = 0; i < indexList.count(); ++i) { QModelIndex index = indexList.at(i); int row = index.row(); int column = index.column(); // 判断是否是单选按钮所在列 if (column == RADIO_BUTTON_COLUMN) { // 获取单选按钮所在的单元格 QModelIndex radioButtonIndex = model->index(row, column); // 获取单选按钮的状态 bool isChecked = model->data(radioButtonIndex, Qt::CheckStateRole).toBool(); // 如果单选按钮被选,输出行号 if (isChecked) { qDebug() << "Selected row: " << row; } } } } ``` 在上述示例,RADIO_BUTTON_COLUMN是单选按钮所在的列号,您需要根据实际情况进行更改。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值