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

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

    3. 使用单元格按钮操作传递多个参数

      时间:2023-07-07
        <tbody id='LZwpf'></tbody>
      <i id='LZwpf'><tr id='LZwpf'><dt id='LZwpf'><q id='LZwpf'><span id='LZwpf'><b id='LZwpf'><form id='LZwpf'><ins id='LZwpf'></ins><ul id='LZwpf'></ul><sub id='LZwpf'></sub></form><legend id='LZwpf'></legend><bdo id='LZwpf'><pre id='LZwpf'><center id='LZwpf'></center></pre></bdo></b><th id='LZwpf'></th></span></q></dt></tr></i><div id='LZwpf'><tfoot id='LZwpf'></tfoot><dl id='LZwpf'><fieldset id='LZwpf'></fieldset></dl></div>
      • <small id='LZwpf'></small><noframes id='LZwpf'>

          <bdo id='LZwpf'></bdo><ul id='LZwpf'></ul>

        • <tfoot id='LZwpf'></tfoot>

              1. <legend id='LZwpf'><style id='LZwpf'><dir id='LZwpf'><q id='LZwpf'></q></dir></style></legend>
                本文介绍了使用单元格按钮操作传递多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                注意:我不需要任何关于使用 UITableview 的 didselect 委托发送数据的建议

                NOTE: i don't need any suggestion regarding sending data using didselect delegate of UITableview

                myButton.h

                #import <UIKit/UIKit.h>
                @interface myButton : UIButton
                {
                    id userData;
                }
                
                @property (strong,nonatomic) NSString* data1;
                
                @end
                

                myButton.m

                #import "myButton.h"
                
                @implementation myButton
                
                /*
                // Only override drawRect: if you perform custom drawing.
                // An empty implementation adversely affects performance during animation.
                - (void)drawRect:(CGRect)rect {
                    // Drawing code
                }
                */
                
                @end
                

                我的 testCollectionViewCell.h 的自定义单元格

                #import "myButton.h"
                @interface testCollectionViewCell : UICollectionViewCell 
                @property (nonatomic,weak) IBOutlet myButton *serviceFav;
                

                我的 testCollectionViewCell.m 自定义单元格

                #import "testCollectionViewCell.h"
                #import <QuartzCore/QuartzCore.h>
                
                @implementation testCollectionViewCell
                 @synthesize serviceFav;
                - (id)initWithFrame:(CGRect)frame
                {
                    self = [super initWithFrame:frame];
                    if (self) {
                        // Initialization code
                
                        //self.serviceFav=[myButton buttonWithType:UIButtonTypeCustom];
                
                    }
                    return self;
                }
                
                
                // Only override drawRect: if you perform custom drawing.
                // An empty implementation adversely affects performance during animation.
                - (void)drawRect:(CGRect)rect
                {
                
                
                
                }
                
                @end
                

                这是我的集合视图委托代码

                And here is my code for the collection view delegate

                - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
                {
                    testCollectionViewCell *cell = [testCollectionViewCell dequeueReusableCellWithReuseIdentifier:@"testCollectionViewCell" forIndexPath:indexPath];
                    cellData = [self.collectionData objectAtIndex:[indexPath row]];
                
                    cell.serviceFav.data1 = @"data1"; **//shows error here and kills**
                
                    [cell.serviceFav addTarget:self action:@selector(touchUpHandler:) forControlEvents:UIControlEventTouchUpInside];
                
                
                    return cell;
                }
                

                //------这不叫----我想叫它

                -(void)touchUpHandler:(myButton*)sender
                {
                
                    UIButton *button = (myButton *)sender; //instance of UIButton
                    NSLog(@"Data 1 = %@",sender.data1);
                }
                

                推荐答案

                我刚刚制作了一个与问题中相同的过程的示例并且它有效.

                I just made a sample with the same process as in the Question and it worked.

                链接:https://www.dropbox.com/s/lb2k7nzsytxjnl2/tabletest.zip?dl=0

                采用自定义按钮类

                MyButton.h

                #import <UIKit/UIKit.h>
                
                @interface MyButton : UIButton
                
                @property (strong,nonatomic) NSString* data1;
                @property (strong,nonatomic) NSString* data2;
                
                @end
                

                MyButton.m

                #import "MyButton.h"
                
                @implementation MyButton
                
                @end
                

                为您的 CustomCell 类制作一个 IBOutlet

                Make an IBOutlet to your CustomCell Class

                CustomTableViewCell.h

                #import <UIKit/UIKit.h>
                #import "MyButton.h"
                
                @interface CustomTableViewCell : UITableViewCell
                @property (weak, nonatomic) IBOutlet MyButton *btnLike;
                
                @end
                

                ViewController.m

                #import "ViewController.h"
                #import "CustomTableViewCell.h"
                
                @interface ViewController ()
                
                @end
                
                @implementation ViewController
                
                - (void)viewDidLoad {
                    [super viewDidLoad];
                    // Do any additional setup after loading the view, typically from a nib.
                }
                
                -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
                    return 5;
                }
                
                -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
                
                    CustomTableViewCell* cell = (CustomTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"CustomTableViewCell"];
                
                    cell.btnLike.data1 = @"data1";
                    cell.btnLike.data2 = @"data2";
                
                    [cell.btnLike addTarget:self action:@selector(touchUpHandler:) forControlEvents:UIControlEventTouchUpInside];
                
                    return cell;
                
                }
                
                - (void) touchUpHandler:(MyButton *)sender {
                
                    NSLog(@"Data 1 = %@",sender.data1);
                    NSLog(@"Data 2 = %@",sender.data2);
                
                }
                @end
                

                单击单元格中的按钮时,它会转到选择器方法 touchUpHandler 并在控制台上打印

                On clicking on the button in the cell, it goes to the selector method touchUpHandler and prints on console

                2016-10-12 23:14:39.034 tabletest[28414:671128] Data 1 = data1
                2016-10-12 23:14:39.035 tabletest[28414:671128] Data 2 = data2
                

                这篇关于使用单元格按钮操作传递多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:iOS - UIPageControl 上的 UIButton 不起作用 下一篇:从 UIPickerView 的选定行设置 UIButton 的标题

                相关文章

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

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

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