Ios 在UITableViewCell-目标C中单击UiImageView后如何访问表格单元格
下面我添加了使用TableViewCell的代码Ios 在UITableViewCell-目标C中单击UiImageView后如何访问表格单元格,ios,objective-c,Ios,Objective C,下面我添加了使用TableViewCell的代码 MyMedsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyMedsTableViewCell" forIndexPath:indexPath]; cell.autoScrolling.hidden = NO; UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] ini
MyMedsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyMedsTableViewCell" forIndexPath:indexPath];
cell.autoScrolling.hidden = NO;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapping:)];
singleTap.numberOfTapsRequired = 1;
[cell.autoScrolling setUserInteractionEnabled:YES];
[cell.autoScrolling addGestureRecognizer:singleTap];
#import <UIKit/UIKit.h>
#import "CustomView.h"
#import <AutoScrollLabel/CBAutoScrollLabel.h>
@interface MyMedsTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet CBAutoScrollLabel *autoScroll;
@property (weak, nonatomic) IBOutlet UIImageView *autoScrolling;
我在这里添加了TableViewCell的头文件
MyMedsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyMedsTableViewCell" forIndexPath:indexPath];
cell.autoScrolling.hidden = NO;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapping:)];
singleTap.numberOfTapsRequired = 1;
[cell.autoScrolling setUserInteractionEnabled:YES];
[cell.autoScrolling addGestureRecognizer:singleTap];
#import <UIKit/UIKit.h>
#import "CustomView.h"
#import <AutoScrollLabel/CBAutoScrollLabel.h>
@interface MyMedsTableViewCell : UITableViewCell
@property (weak, nonatomic) IBOutlet CBAutoScrollLabel *autoScroll;
@property (weak, nonatomic) IBOutlet UIImageView *autoScrolling;
我试过不同的方法,但还是不行。有人能帮忙吗?据我所知,您在标题中的三个蓝色虚线图像视图中检测到点击有问题 因此,解决方案是使用UIButton而不是标题中的UIImageView为button image属性设置三个蓝色虚线图像 在你的牢房里等待使用
cell.myButton.tag = indexPath.row;
现在在viewController类中为该按钮添加操作
- (IBAction)myButton:(UIButton *)sender {
// Here you can identify button by its tag value
NSLog(@"Button %ld tapped", (long)sender.tag);
}
据我所知,您在标题中的三个蓝色虚线图像视图中检测到点击有问题 因此,解决方案是使用UIButton而不是标题中的UIImageView为button image属性设置三个蓝色虚线图像 在你的牢房里等待使用
cell.myButton.tag = indexPath.row;
现在在viewController类中为该按钮添加操作
- (IBAction)myButton:(UIButton *)sender {
// Here you can identify button by its tag value
NSLog(@"Button %ld tapped", (long)sender.tag);
}
1) 在UIImageView的前面使用UIBUtton是更好的选择
2) 如果无法使用1)并且必须使用UIImageview,则可以使用以下方法访问单元格:
首先将Imageview的标记分配给Indexpath.row
cell.autoScrolling.tag = indexPath.row;
您可以在TapGestureRecognizer方法中使用此标记
-(void)singleTapping:(UIGestureRecognizer *)recognizer {
UIImageView *autoScrolling = (UIImageView *)[recognizer view];
long tag = autoScrolling.tag;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:tag inSection:0];
MyMedsTableViewCell *cell = (MyMedsTableViewCell *)[tblRegister cellForRowAtIndexPath:indexPath];
//You can access property of cell now.
}
1) 在UIImageView的前面使用UIBUtton是更好的选择
2) 如果无法使用1)并且必须使用UIImageview,则可以使用以下方法访问单元格:
首先将Imageview的标记分配给Indexpath.row
cell.autoScrolling.tag = indexPath.row;
您可以在TapGestureRecognizer方法中使用此标记
-(void)singleTapping:(UIGestureRecognizer *)recognizer {
UIImageView *autoScrolling = (UIImageView *)[recognizer view];
long tag = autoScrolling.tag;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:tag inSection:0];
MyMedsTableViewCell *cell = (MyMedsTableViewCell *)[tblRegister cellForRowAtIndexPath:indexPath];
//You can access property of cell now.
}
是否启用了“UIImageview”的
userInteraction
?如果tableView没有那么复杂,您可以使用标记。@Larme如何将标记传递给方法,以及如何使用tag@Dimple方法在我单击时调用。您需要解释最后要执行的操作,因为它可以更改方法,还有您有多少节/行。“UIImageview”的userInteraction
是否已启用?如果您的tableView没有那么复杂,您可以使用标记。@Larme如何将标记传递给方法,以及如何使用tag@Dimple方法在我单击时调用。您需要解释最后要执行的操作,因为它可以改变方法,也可以改变你有多少节/行。