0

選択すると、「はい」または「いいえ」の確認でポップアップが表示されます。「はい」を選択するUITableViewと、セルの高さを 100 に増やし、背景画像を変更する必要があります。「いいえ」の場合を選択すると、何も起こらず、通常のセルのままになります...

同様に、すでに選択されているセルが選択されている場合、再び「はい」または「いいえ」の確認のポップアップが表示されます。「はい」を選択すると、選択したセルが高さ 44 の通常のセルに変換され、背景画像が削除されます。「いいえ」を選択すると何も起こらずセルは選択セルのまま…

このような状態での高さの変化と背景画像の変化にどのように対処するのですか????

#import "TableViewController.h"

@interface TableViewController ()

@end

@implementation TableViewController

- (id)initWithStyleUITableViewStyle)style
{
    self = [super initWithStyle:style];
   if (self)
   {
       objects = [NSArray   arrayWithObjects:@"One",@"Two",@"Three",@"Four",@"Five",@"Six",@"Seven",@"Eight",@"Nine",@"       Ten",@"Eleven",@"Twelve",@"Thirteen", nil];
         selectedIndexPath = [[NSIndexPath alloc] init];
  }
   return self;
}




 - (NSInteger)numberOfSectionsInTableViewUITableView *)tableView
{

// Return the number of sections.
    return 1;
 }

 - (NSInteger)tableViewUITableView *)tableView numberOfRowsInSectionNSInteger)section
 {

    // Return the number of rows in the section.
    return [objects count];
 }

 - (UITableViewCell *)tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath      *)indexPath
 {
     NSString *CellIdentifier = [NSString stringWithFormat:@"Cell %d",indexPath.row];
     UITableViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil)
    {
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseI  dentifier:CellIdentifier];
       cell.textLabel.text = [objects objectAtIndex:indexPath.row];

       NSLog(@"cell description:- %@",[cell description]);
   }


   return cell;


  }

   - (CGFloat)tableViewUITableView *)tableView heightForRowAtIndexPathNSIndexPath *)indexPath
   {

  //    if (indexPath == selectedIndexPath)
  //    {
  //        return  100 ;
  //    }
  //    if (indexPath == selectedIndexPath)
  //    {
  //        UITableViewCell *c = [self.tableView cellForRowAtIndexPath:indexPath];
  //        CGRect rect = c.frame ;
  //        rect.size.height = 100 ;
  //        c.frame = rect ;
  //        return  100;
  //    }

      return  44;
 }

  -(void)tableViewUITableView *)tableView didSelectRowAtIndexPathNSIndexPath *)indexPath
 {
    if (selectedIndexPath == [self.tableView indexPathForSelectedRow])
     {
         UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"DeSelect" message:@"DeSelect ??" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"Yes", nil ];
         [a show];
    }
   else
  {
     UIAlertView *a = [[UIAlertView alloc] initWithTitle:@"Select" message:@"Select ??" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"Yes", nil ];
    [a show];
   }
}
 -(void)alertViewUIAlertView *)alertView clickedButtonAtIndexNSInteger)buttonIndex
  {
       if (selectedIndexPath == [self.tableView indexPathForSelectedRow])
     {
         if (buttonIndex==1)
       {
         selectedIndexPath = [NSIndexPath indexPathForRow:-1 inSection:-1];
          // [self tableView:self.tableView heightForRowAtIndexPath:selectedIndexPath];
        //[self.tableView reloadData];
          //[self.tableView reloadRowsAtIndexPaths:[NSArray   arrayWithObject:selectedIndexPath] withRowAnimation:UITableViewRowAnimationFade];
        //[self.tableView beginUpdates];
        //[self.tableView endUpdates];
        [self showForIndexPath:selectedIndexPath];
        [self.tableView beginUpdates];
        [self.tableView endUpdates];

    }
     }
     else
     {
       if (buttonIndex==1)
    {
        selectedIndexPath = [self.tableView indexPathForSelectedRow];
        //[self tableView:self.tableView heightForRowAtIndexPath:selectedIndexPath];
        //[self.tableView reloadData];
       //[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:selectedIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
      // [self.tableView beginUpdates];
     //  [self.tableView endUpdates];
          [self showForIndexPath:selectedIndexPath];
          [self.tableView beginUpdates];
          [self.tableView endUpdates];

      }
    }
    }
    -(void)showForIndexPathNSIndexPath *)indexpath
 {

    UITableViewCell *c = [self.tableView cellForRowAtIndexPath:indexpath];
    CGRect rect = c.frame ;
    rect.size.height = 100 ;
    c.frame = rect ;
    //code to move the cells downward when a cell is selected 
    for(int i = indexpath.row ; i < [objects count];i++)
   {
      NSindexpath *row = [NSIndexPath indexPAthforRow:i+1 in Section:0];
      UITableViewCell *tmp = [self.tableView cellforindexpath:row];
      CGRect frame = tmp.frame;
      CGpoint origin = frame.origin;
      CGFloat y = origin.y ;
      y = y+56; //(100-44)
      origin.y = y ;
      frame.origin = origin ;
      tmp.frame = frame ;
   }

    NSLog(@"Cell %d :- %@ indexpath:- %@",indexpath.row,[c description],indexpath);
 }

PS - コメントされているコードを見ると、タスクを達成するために私が行った試みを見ることができます

4

3 に答える 3

1

あなたが試したコードを投稿してください。このリンクが役立つ場合があります。 選択したときに UITableViewCell の高さの変化をアニメーション化できますか? .

ポップアップ ボタン インデックスを使用して変数値を変更し、その変数を

    -(CGFloat)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//change tablecell height based on variable value
}
    -(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
        if (buttonIndex == 0) {

        }
    }
于 2013-02-28T05:12:31.243 に答える
1

はいまたはいいえのフラグと、選択した行番号のインデックスを保持します。

 -(CGFloat)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
 {
      if ( flag == 1 && indexpath.row == index )
            return 50;  
      else
            return 30;


 }

セルを作成するときにも同様に画像のロジックを適用します

于 2013-02-28T05:07:34.043 に答える
0

tableViewCell両方の場合に2 つ作成します。次に、buttonTouchメソッドで、前のセルを削除します

- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

そして、次を使用して newCell を追加します。

- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
于 2013-02-28T05:23:09.117 に答える