Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在UITableViewCell中正确隐藏UIButton_Ios_Objective C_Uitableview_Uibutton - Fatal编程技术网

Ios 在UITableViewCell中正确隐藏UIButton

Ios 在UITableViewCell中正确隐藏UIButton,ios,objective-c,uitableview,uibutton,Ios,Objective C,Uitableview,Uibutton,我有一个UIButton,我只想在UITableViewCell的某些实例中出现。根据用户输入的信息,该按钮将对他们可用。但是,当我删除具有“可见”按钮的单元格时,显示指令的默认单元格仍保留一个不需要的可见按钮 以下是我的CellForRowatineXpath代码: 以下是我的减法药丸按钮代码: - (void)subtractPill:(id)sender { NSIndexPath *indexPath = [self.tableView indexPathForCell:

我有一个UIButton,我只想在UITableViewCell的某些实例中出现。根据用户输入的信息,该按钮将对他们可用。但是,当我删除具有“可见”按钮的单元格时,显示指令的默认单元格仍保留一个不需要的可见按钮

以下是我的CellForRowatineXpath代码:

以下是我的减法药丸按钮代码:

- (void)subtractPill:(id)sender
{
    NSIndexPath *indexPath =
    [self.tableView indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
    NSUInteger row = indexPath.row;
    Medicine *x = [self.delegate.medicineList objectAtIndex:row];
    [x decreaseBy:1];
    [self.tableView reloadData];
}
这是我在tableview中编辑和删除单元格的代码

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    if (self.delegate.medicineList.count==0) {
        return NO;
    }
    return YES;
}




- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
        [self.delegate.medicineList removeObjectAtIndex:indexPath.row];
    [self.tableView reloadData];

}
现在,显示单词的默认单元格点击+按钮添加药物。删除该单元格时,与“减法”按钮重叠。换句话说,删除包含按钮的单元格时,按钮不会不可见。
我还试图改变按钮的框架,使其在屏幕上不可见,但这也不起作用。我是在研究了类似的问题后来到这里的,并得出结论,按钮的隐藏属性有一个小故障或一个我还没有意识到的特征。任何帮助都将不胜感激

看来我回答了自己的问题:我只是把隐藏的财产放错了地方。我仍然不完全理解为什么它不起作用,但是当我将隐藏属性放置在tableview的编辑和删除方法中时,按钮不再出现

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    if (self.delegate.medicineList.count==0) {
        return NO;
    }
    return YES;
}




- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
        [self.delegate.medicineList removeObjectAtIndex:indexPath.row];
    [self.tableView reloadData];

}