Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.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
iPhone sdk如何在两次不同的按钮点击中添加/删除UIButton_Iphone_Uibutton_Hidden - Fatal编程技术网

iPhone sdk如何在两次不同的按钮点击中添加/删除UIButton

iPhone sdk如何在两次不同的按钮点击中添加/删除UIButton,iphone,uibutton,hidden,Iphone,Uibutton,Hidden,我有两个单独的按钮,分别用于在UITableView中按升序和降序对数组进行排序 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { checkButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; checkButton.frame = CGRec

我有两个单独的按钮,分别用于在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];
}
接下来,当我单击“排序”按钮时,这两个“检查”按钮应该出现,而当我单击“完成”按钮时,这两个按钮应该消失

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

现在,我的排序功能运行良好。但当我点击“完成”按钮时,我的按钮并没有从单元格路径中消失,因为我给出了条件,让按钮位于第一个和最后一个索引上。如何仅在单击“完成”按钮时隐藏我的两个按钮?提前非常感谢。

也请尝试在doneClick中调用reload data

[editTable reloadData];

试着先在谷歌上搜索,然后再在软件上提问,因为这可能是重复的问题

h

m


表格视图的开始和结束更新中,给出
按钮
方法块。像

-(void)doneClick:(id)sender
{
   NSLog(@"Done Clicked");
   [tableView beginUpdates];
   if (appDelegate.b == 400) 
   {
        checkButton.hidden = YES;
        checkButton1.hidden = YES;
   }
   [tableView endUpdates];
   self.navigationItem.title = @"Edit Book Shelf";

   sortButton.hidden = NO;
   editButton.hidden = NO;
   doneButton.hidden = YES;
}

我不能清楚地理解你的问题。。。。那么,你想要什么???请简写:)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //  . . Some Code . . .
    if ( selectedIndexPath.row = indexPath.row &&  selectedIndexPath.section = indexPath.section ) {
        button1.hidden = NO;
        button2.hidden = NO;
    } else {
        button1.hidden = YES;
        button2.hidden = YES;
    }
    //  . . Some Code . . .
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    selectedIndexPath = indexPath;
    [tableView relaodData];
}
-(void)doneClick:(id)sender
{
   NSLog(@"Done Clicked");
   [tableView beginUpdates];
   if (appDelegate.b == 400) 
   {
        checkButton.hidden = YES;
        checkButton1.hidden = YES;
   }
   [tableView endUpdates];
   self.navigationItem.title = @"Edit Book Shelf";

   sortButton.hidden = NO;
   editButton.hidden = NO;
   doneButton.hidden = YES;
}