IOS cell中,点击button时,确定哪一行的button被点击了。

通过在TableView创建cell时,获取button的tag值,然后赋值给button。

当button点击时,然后就有了一个tag。然后就可以区分开点击了哪一个button了。

UITableView.m中定义

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

{

  [cell setSubTag:indexPath.row];

}

cell.m中定义如下

- (void)jumpSellOptionButton : (id)sender{

    

    NSLog(@"welcome !!!!  tag=%ld", ((UIButton *)sender).tag);

}

- (void)setSubTag:(NSInteger)aTag

{

    _pBuyButton.tag = aTag;

    _exeSellButton.tag = aTag;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,在CreateOutboundViewController,你需要在点击删除按钮候弹出CreateOutboundDeletePopupView弹窗。可以通过在按钮点击事件创建弹窗视图并将其添加到当前视图上来实现: ```objc - (IBAction)deleteButtonTapped:(id)sender { CreateOutboundDeletePopupView *deletePopupView = [[CreateOutboundDeletePopupView alloc] initWithFrame:self.view.frame]; deletePopupView.delegate = self; [self.view addSubview:deletePopupView]; } ``` 接下来,你需要在CreateOutboundDeletePopupView添加一个确定按钮,并在点击确定按钮触发向后台请求数据的操作。可以通过在确定按钮点击事件调用代理方法来实现: ```objc - (IBAction)confirmButtonTapped:(id)sender { // 向后台请求数据并删除 // ... // 关闭弹窗 [self removeFromSuperview]; // 调用代理方法,通知CreateOutboundViewController删除成功 if ([self.delegate respondsToSelector:@selector(deleteSuccessful)]) { [self.delegate deleteSuccessful]; } } ``` 在CreateOutboundViewController,需要实现代理方法deleteSuccessful,该方法将在CreateOutboundDeletePopupView确定按钮点击后被调用。在该方法,你需要更新tableview的cell,将删除后的cellbutton按钮显示出来。可以通过刷新tableview来实现: ```objc - (void)deleteSuccessful { // 更新tableview [self.tableView reloadData]; } ``` 在tableview的cell,你需要根据cell的状态来判断是否显示button按钮。可以通过在cellForRowAtIndexPath代理方法设置cell的状态来实现: ```objc - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; // 根据cell的状态来设置button按钮是否显示 if (cell.isSelected) { cell.button.hidden = NO; cell.userInteractionEnabled = YES; } else { cell.button.hidden = YES; cell.userInteractionEnabled = NO; } return cell; } ``` 在CreateOutboundViewController,你可以在网络请求成功后调用reloadData方法刷新tableview,并在代理方法deleteSuccessful调用该方法: ```objc - (void)deleteSuccessful { // 向后台请求数据并删除 // ... // 更新tableview [self.tableView reloadData]; } ``` 最后,你需要在CreateOutboundDeletePopupView添加一个代理属性,并在CreateOutboundViewController实现该代理协议: ```objc @protocol CreateOutboundDeletePopupViewDelegate <NSObject> - (void)deleteSuccessful; @end @interface CreateOutboundDeletePopupView : UIView @property (nonatomic, weak) id<CreateOutboundDeletePopupViewDelegate> delegate; @end ``` 这样,当你在CreateOutboundDeletePopupView确定按钮点击后,就可以调用代理方法通知CreateOutboundViewController删除成功,然后更新tableview的cell,将删除后的cellbutton按钮显示出来。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值