(IOS)当我想在一个单元格中禁用一个按钮时,它会禁用许多其他按钮

(IOS)当我想在一个单元格中禁用一个按钮时,它会禁用许多其他按钮,ios,button,tags,sender,Ios,Button,Tags,Sender,我正在制作一个ios应用程序。我的问题是,当我想在一个单元格中禁用一个按钮时,它会禁用许多其他按钮。我尝试了很多问题,但我真的不知道为什么。按钮的标签没问题,我想我没有正确使用发送器。我的代码如下所示: - (IBAction) fiyeItPressed:(UIButton*)sender { UIButton *fiyeItButton = (UIButton*) sender; [fiyeItButton setEnabled:NO]; NSLog(@"%d",[

我正在制作一个ios应用程序。我的问题是,当我想在一个单元格中禁用一个按钮时,它会禁用许多其他按钮。我尝试了很多问题,但我真的不知道为什么。按钮的标签没问题,我想我没有正确使用发送器。我的代码如下所示:

- (IBAction) fiyeItPressed:(UIButton*)sender
{
    UIButton *fiyeItButton = (UIButton*) sender;

    [fiyeItButton setEnabled:NO];
    NSLog(@"%d",[fiyeItButton tag]);

    NSString *FiyeNumberString = [playlistVote objectAtIndex:sender.tag];
    int FiyeInt = [FiyeNumberString intValue] + 1;
    FiyeNumberString = [NSString stringWithFormat:@"%d",FiyeInt];
    [playlistVote  replaceObjectAtIndex:sender.tag withObject:FiyeNumberString];

    [self saveForTable];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    PlaylistTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    cell.SongName.text = [playlistSongTitle objectAtIndex:indexPath.row];
    cell.ArtisteName.text = [playlistSongArtist objectAtIndex:indexPath.row];
    cell.numberOfVote.text = [playlistVote objectAtIndex:indexPath.row];
    cell.VoteButton.tag = indexPath.row;

    return cell;
}

由于您正在重用TableView单元格,这意味着当您开始在TableView中滚动时,带有禁用按钮的单元格最终将被重用并显示。您需要做的是在CellForRowAtIndexPath中将按钮主动设置为enabled(启用)或disabled(禁用)


我建议您跟踪按钮已按下的索引,然后使用该信息确定在CellForRowAtIndexPath方法中是否应启用或禁用按钮。

查看您已经拥有的内容,似乎最简单的“快速修复”方法就是使用另一个数组,如playlistSongTitle等

它所需要做的就是有一些布尔值来跟踪按钮是否启用。然后在您的CellForRowatineXpath:方法中,您所需要的就是

[cell.voteButton setEnabled:[playlistButtonsEnabled objectAtIndex:indexPath.row]];
您可能需要先提取bool,但不确定它是否能正确推断类型。 然后在fiyeItPressed:方法中,只需将BOOL调整为YES或NO


希望这对您有所帮助

如何在单元格(您的代码)中禁用按钮?如下所示:在fiyeit按钮操作中[fiyeItButton setEnabled:NO];