我有两个单独的按钮,用于分别在 UITableView 中按升序和降序对数组进行排序。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
checkButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
checkButton.frame = CGRectMake(540, 30, 42, 42);
[checkButton setBackgroundImage:[[UIImage imageNamed:@"Down Arrow.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0] forState:UIControlStateNormal];
[checkButton addTarget:self action:@selector(descender:) forControlEvents:UIControlEventTouchUpInside];
[checkButton setTag:200];
[cell.contentView addSubview:checkButton];
checkButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
checkButton1.frame = CGRectMake(600, 30, 42, 42);
[checkButton1 setBackgroundImage:[[UIImage imageNamed:@"Up Arrow.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0] forState:UIControlStateNormal];
[checkButton1 addTarget:self action:@selector(ascender:) forControlEvents:UIControlEventTouchUpInside];
[checkButton1 setTag:100];
[cell.contentView addSubview:checkButton1];
checkButton = (UIButton *)[cell viewWithTag:200];
if (indexPath.row == 0 && appDelegate.a == 300)
{
checkButton.hidden = NO;
checkButton1.hidden = YES;
}
checkButton1 = (UIButton *)[cell viewWithTag:100];
if ((lastSectionIndex == indexPath.section && lastRowIndex == indexPath.row ))
{
checkButton.hidden = YES;
checkButton1.hidden = NO;
}
}
在 cellforrowAtIndexPath 中,我添加了两个用于排序的按钮。现在,当我单击排序按钮时,该排序按钮应该消失并且必须出现完成按钮。我给它如下,
-(void)sortItem:(id)sender
{
NSLog(@"sort clicked");
if(appDelegate.a = 300)
{
checkButton.hidden = NO;
checkButton1.hidden = YES;
}
self.navigationItem.title = @"Sort Book Shelf";
sortButton.hidden = YES;
editButton.hidden = YES;
doneButton.hidden = NO;
// if (appDelegate.b == 400)
// {
// checkButton.hidden = NO;
// checkButton1.hidden = NO;
// }
[editTable reloadData];
}
接下来,当我单击 SORT 按钮这两个检查按钮时,检查按钮 1 应该出现,当我单击 DONE 按钮时,这两个按钮应该消失。
-(void)doneClick:(id)sender
{
NSLog(@"Done Clicked");
if (appDelegate.b == 400)
{
checkButton.hidden = YES;
checkButton1.hidden = YES;
}
self.navigationItem.title = @"Edit Book Shelf";
sortButton.hidden = NO;
editButton.hidden = NO;
doneButton.hidden = YES;
}
现在,排序功能运行良好。但是当我点击完成按钮时,我的按钮并没有从单元格路径中消失,因为我给出了将按钮放在第一个和最后一个索引上的条件。如何仅在单击完成按钮时隐藏我的两个按钮?提前非常感谢。