tracifycray
tracifycray

Reputation: 1423

Error with action:@selector in app

I'm creating an app were users should be able to report posts. I want an actionsheet when the user press the report button. This is my code:

[self.avatarImageView.profileButton addTarget:self action:@selector(didTapReportButtonAction:) forControlEvents:UIControlEventTouchUpInside];

and here is the didTapReportButtonAction code:

- (void)didTapReportButtonAction:(UIButton *)button {
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Title" delegate:nil cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destructive" otherButtonTitles:@"Other1", @"Other2", nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
    [actionSheet addButtonWithTitle:@"Add"];
    [actionSheet showInView:[UIApplication sharedApplication].keyWindow];
}

But when I try to press the report button now, nothing happens. Can someone help me with this?

Upvotes: 0

Views: 55

Answers (2)

Avi Tsadok
Avi Tsadok

Reputation: 1843

If avatarImageView is an UIImageView, its userinteraction property is false by default. this means the event won't called.

make sure avatarImageView.userInteraction = YES

Upvotes: 1

Praveen Castelino
Praveen Castelino

Reputation: 69

Can you try this:

[actionSheet showInView:self.view];

Upvotes: 1

Related Questions