ActionSheet 不断出现在每个按钮上

ActionSheet keeps appearing for every button

我有一个方法可以抛出一个由数组填充的 actionSheet。

问题是,一旦我将该方法放入 1 个按钮的发送器中,它就会在 次按下单个按钮时触发。

我只希望它显示一个按钮 (btnPortfolio)。

这是我的按钮的代码:

 - (IBAction)btnPortfolio:(id)sender {
    [self populatePortfolioList];
 }

- (IBAction)btnAdd:(id)sender {

}

- (IBAction)btnRefresh:(id)sender {
}

这是我的方法:

-(void)populatePortfolioList{
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Choose your option"
                                                             delegate:self
                                                    cancelButtonTitle:nil
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:nil];
    for (NSString *title in portfolio_list) {
        [actionSheet addButtonWithTitle:title];
    }
    actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];
    [actionSheet showInView:self.view];
}

因为您使用的是 IBActions,我假设您已经通过 ctrl+从按钮拖动到您的代码中以某种方式创建了方法?是这样吗?您可能不小心使用 btnPortfolio 方法连接了多个按钮,这会导致每次按下按钮时调用 populatePortfolioList