<i id='HfUDc'><tr id='HfUDc'><dt id='HfUDc'><q id='HfUDc'><span id='HfUDc'><b id='HfUDc'><form id='HfUDc'><ins id='HfUDc'></ins><ul id='HfUDc'></ul><sub id='HfUDc'></sub></form><legend id='HfUDc'></legend><bdo id='HfUDc'><pre id='HfUDc'><center id='HfUDc'></center></pre></bdo></b><th id='HfUDc'></th></span></q></dt></tr></i><div id='HfUDc'><tfoot id='HfUDc'></tfoot><dl id='HfUDc'><fieldset id='HfUDc'></fieldset></dl></div>
      <legend id='HfUDc'><style id='HfUDc'><dir id='HfUDc'><q id='HfUDc'></q></dir></style></legend>
      • <bdo id='HfUDc'></bdo><ul id='HfUDc'></ul>

      <small id='HfUDc'></small><noframes id='HfUDc'>

        <tfoot id='HfUDc'></tfoot>
      1. 如何在iOS中通过参数将UITableView IndexPath传递给UIButton @selector?

        时间:2023-07-08

        1. <tfoot id='yUUdU'></tfoot>
          <i id='yUUdU'><tr id='yUUdU'><dt id='yUUdU'><q id='yUUdU'><span id='yUUdU'><b id='yUUdU'><form id='yUUdU'><ins id='yUUdU'></ins><ul id='yUUdU'></ul><sub id='yUUdU'></sub></form><legend id='yUUdU'></legend><bdo id='yUUdU'><pre id='yUUdU'><center id='yUUdU'></center></pre></bdo></b><th id='yUUdU'></th></span></q></dt></tr></i><div id='yUUdU'><tfoot id='yUUdU'></tfoot><dl id='yUUdU'><fieldset id='yUUdU'></fieldset></dl></div>

              <small id='yUUdU'></small><noframes id='yUUdU'>

                • <bdo id='yUUdU'></bdo><ul id='yUUdU'></ul>
                • <legend id='yUUdU'><style id='yUUdU'><dir id='yUUdU'><q id='yUUdU'></q></dir></style></legend>

                    <tbody id='yUUdU'></tbody>
                  本文介绍了如何在iOS中通过参数将UITableView IndexPath传递给UIButton @selector?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 UITableViewCells 中添加了 UIButton.我有当用户单击按钮时,我们获得了 indexpath 以使用来自 NSMutableArray 的值.我已经使用下面的来获取当前的 IndexPath,

                  I have added UIButton in UITableViewCells. I have when the user clicks the button we have get the indexpath to use the values from NSMutableArray. I have used the below to get the current IndexPath,

                  [getMeButton addTarget:self action:@selector(resendTheErrorMessage:) forControlEvents:UIControlEventTouchUpInside];
                  
                  -(void) resendTheErrorMessage:(id)sender 
                  {
                     NSLog(@"SEnder: %@", sender);
                     //NSLog(@"Index Path : %@", indexpath);
                  }
                  

                  谁能帮我传递当前的 indexpath UIButton's @selector.提前致谢.

                  Can anyone please help me to pass current indexpath UIButton's @selector. Thanks in advance.

                  这是我从 NSLog()

                  <UIButton: 0x864d420; frame = (225 31; 95 16); opaque = NO; tag = 105; layer = <CALayer: 0x864d570>>
                  

                  推荐答案

                  添加你的 UIButton 像这样

                  UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
                  [btn setFrame:CGRectMake(10.0, 2.0, 140.0, 40.0)];
                  [btn setTitle:@"ButtonTitle" forState:UIControlStateNormal];
                  [btn addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
                  [btn setTag:indexPath.row];
                  [cell.contentView addSubview:btn];
                  

                  然后得到它的标签号——

                  And then get its tag number -

                  -(void)buttonClicked:(id)sender
                  {
                      NSLog(@"tag number is = %d",[sender tag]);
                      //In this case the tag number of button will be same as your cellIndex.
                     // You can make your cell from this.
                  
                     NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[sender tag] inSection:0];
                     UITableViewCell *cell = [tblView cellForRowAtIndexPath:indexPath];
                  }
                  

                  注意: 当您的 tableView 只有 1 个部分时,上述解决方案将起作用.如果您的 tableView 有多个部分,您应该知道您的部分索引或使用以下方法.

                  替代方案:1

                  UIView *contentView = (UIView *)[sender superview];
                  UITableViewCell *cell = (UITableViewCell *)[contentView superview];
                  NSIndexPath *indexPath = [tblView indexPathForCell:cell];
                  

                  替代方案:2

                  CGPoint touchPoint = [sender convertPoint:CGPointZero toView:tblView];
                  NSIndexPath *indexPath = [tblView indexPathForRowAtPoint:touchPoint];
                  UITableViewCell *cell = [tblView cellForRowAtIndexPath:indexPath];
                  

                  这篇关于如何在iOS中通过参数将UITableView IndexPath传递给UIButton @selector?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:UIbutton标题上的自定义字体夹在单词的顶部 下一篇:保持 iPhone UIButton 突出显示

                  相关文章

                  • <bdo id='zSw40'></bdo><ul id='zSw40'></ul>

                      <legend id='zSw40'><style id='zSw40'><dir id='zSw40'><q id='zSw40'></q></dir></style></legend>

                    1. <tfoot id='zSw40'></tfoot>

                      <small id='zSw40'></small><noframes id='zSw40'>

                    2. <i id='zSw40'><tr id='zSw40'><dt id='zSw40'><q id='zSw40'><span id='zSw40'><b id='zSw40'><form id='zSw40'><ins id='zSw40'></ins><ul id='zSw40'></ul><sub id='zSw40'></sub></form><legend id='zSw40'></legend><bdo id='zSw40'><pre id='zSw40'><center id='zSw40'></center></pre></bdo></b><th id='zSw40'></th></span></q></dt></tr></i><div id='zSw40'><tfoot id='zSw40'></tfoot><dl id='zSw40'><fieldset id='zSw40'></fieldset></dl></div>