Ios 在表视图目标c中的按钮上添加操作
我必须为此添加警报按钮。我希望按钮上的操作能够尽快完成。我已经编写了此代码以打开警报Ios 在表视图目标c中的按钮上添加操作,ios,objective-c,tableview,Ios,Objective C,Tableview,我必须为此添加警报按钮。我希望按钮上的操作能够尽快完成。我已经编写了此代码以打开警报 cell.btnCommentOption.tag = indexPath.row; if([Boomerang sharedManager].currentUser.user_id != comment.user.user_id){ cell.btnCommentOption.hidden = YES; [cell.btnComm
cell.btnCommentOption.tag = indexPath.row;
if([Boomerang sharedManager].currentUser.user_id != comment.user.user_id){
cell.btnCommentOption.hidden = YES;
[cell.btnCommentOption addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
}
按钮的动作是
- (IBAction)btnCommentOptionsTapped:(UIButton*)sender {
UIAlertController * alert = [UIAlertController
alertControllerWithTitle:@"Share"
message:@""
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* sharefeed = [UIAlertAction
actionWithTitle:@"Share feed"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[alert dismissViewControllerAnimated:YES completion:^{}];
}];
UIAlertAction* report = [UIAlertAction
actionWithTitle:@"Report"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[alert dismissViewControllerAnimated:YES completion:^{}];
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[alert dismissViewControllerAnimated:YES completion:^{}];
}];
[alert addAction:sharefeed];
[alert addAction:report];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil]
}
当我将操作添加到按钮时,出现错误,请帮助我解决此错误是
不可见@interface for UIImageView declears选择器addTarget:action:forcontrolEvents
检查您的操作名称是否正确
[cell.btnCommentOption addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
或
更新答案
if([Boomerang sharedManager].currentUser.user_id == comment.user.user_id){
cell.btnCommentOption.hidden = NO;
[cell.btnCommentOption addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
}else
{
cell.btnCommentOption.hidden = YES;
}
并将您的按钮操作称为
- (IBAction)didTapButton:(UIButton*)sender {
不是
最后一次上升
“UIImageView没有不可见的@界面可清除选择器addTarget:action:forcontrolEvents”
错误显示cell.btncommentonoption是UIimageview而不是UIButton
UIImageView
不是一个UIControl
,因此它没有addTarget:action:forControlEvents
方法作为其界面的一部分。您可以改用手势识别器
在cellforrowatinexpath
方法中添加此代码
cell. btnCommentOption.userInteractionEnabled = YES;
cell. btnCommentOption.tag = indexPath.row;
cell.btnCommentOption.hidden = YES;
if([Boomerang sharedManager].currentUser.user_id == comment.user.user_id){
cell.btnCommentOption.hidden = NO;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(btnCommentOptionsTapped:)];
tap.numberOfTapsRequired = 1;
[cell.btnCommentOption addGestureRecognizer:tap];
}
并将该方法称为
- (void)btnCommentOptionsTapped:(UITapGestureRecognizer *)sender {
“UIImageView没有不可见的@界面可清除选择器addTarget:action:forcontrolEvents”
发生此错误是因为addTarget方法是按钮的,并且您正试图在UIImageView上调用它。请检查自定义单元格中的出口参考。附加到
btnCommentOption
的参考不是按钮,而是UIImageView。错误是什么这一个是正确的cell.btnCommentOption.hidden=YES
或此项正确cell.btnCommentOption.hidden=NO代码>如果您在条件内部调用更新,请仔细查看我已从条件外部调用了操作,但存在相同的问题您是否可以显示与此相关的addtargetbtncommentonoptions点击
这不是一个问题我已经做了很多次,并且在我的最后一个问题中出现了相同的错误您是否添加了addTarget:action:forcontrolEvents
对于您的图像视图,如果是,请将addTarget:action:forcontrolEvents
更改为点击手势,@HusnainAli-cell.btn提示选项是UIimageview或UIButton
cell. btnCommentOption.userInteractionEnabled = YES;
cell. btnCommentOption.tag = indexPath.row;
cell.btnCommentOption.hidden = YES;
if([Boomerang sharedManager].currentUser.user_id == comment.user.user_id){
cell.btnCommentOption.hidden = NO;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(btnCommentOptionsTapped:)];
tap.numberOfTapsRequired = 1;
[cell.btnCommentOption addGestureRecognizer:tap];
}
- (void)btnCommentOptionsTapped:(UITapGestureRecognizer *)sender {