操作错误:app中的@selector

时间:2013-04-20 18:22:50

标签: ios uiactionsheet

我正在创建一个应用程序,用户应该能够报告帖子。当用户按下报告按钮时,我想要一个操作表。 这是我的代码:

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

这里是didTapReportButtonAction代码:

- (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];
}

但是当我现在尝试按下报告按钮时,没有任何反应。 有人可以帮我这个吗?

2 个答案:

答案 0 :(得分:1)

如果avatarImageView是UIImageView,则默认情况下其userinteraction属性为false。 这意味着事件不会被调用。

确保avatarImageView.userInteraction = YES

答案 1 :(得分:1)

你可以试试这个:

[actionSheet showInView:self.view];