0

で選択した後に新しい「アーツ」メニューを表示できない理由を特定しようとしていますがdidSelectRowAtIndexPath.、正しく使用されていないことに気付きました...また、2回タップした後に表示する方法はありますか、didSelectRowAtIndexPathまたはデフォルトは一度押すだけで動作しますか?

-(void)viewDidAppear:(BOOL)animated
{
 NSString *arts = @"Arts and Museums";

 [arrayNo addObject:arts];

 [[self myTableView] reloadData];
}

- (void)viewDidLoad
{
 [super viewDidLoad];
 arrayNo = [[NSMutableArray alloc] init];
 [[self myTableView] setDelegate:self];
 [[self myTableView] setDataSource:self];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
 return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 return [arrayNo count];
}

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

  if (!cell)
  {
    NSLog(@"CREATING NEW CELL");
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    cell.textLabel.textColor = [UIColor colorWithRed:(100/255.0) green:(130/255.0) blue:(255/255.0) alpha:1.0];
  }

  cell.textLabel.text = [arrayNo objectAtIndex:indexPath.row];

  return cell;
}

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

  if ([cell.textLabel.text isEqualToString: @"Arts and Museums"])
  {
    NSString *galleries = @"Art Galleries";
    NSString *dramatic = @"Dramatic Arts";
    NSString *museums = @"Museums";

    [arrayNo addObject:galleries];
    [arrayNo addObject:dramatic];
    [arrayNo addObject:museums];

   [self.myTableView reloadData];
  }
}

** * ** * ** * ***更新しました** * ** * ** * ****

以下のコードで更新didSelectRowAtIndexPathした後、それを参照していることがわかりますが、古い配列を置き換えるために新しいメニュー項目が表示されません。データを使用self.myTableView = nilしてリロードしようとしましたが、効果がないように見えますか?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    if ([cell.textLabel.text isEqualToString: @"Arts and Museums"])
    {
      NSString *galleries = @"Art Galleries";
      NSString *dramatic = @"Dramatic Arts";
      NSString *museums = @"Museums";

      [arrayNo addObject:galleries];
      [arrayNo addObject:dramatic];
      [arrayNo addObject:museums];

      NSLog(@"LOADED");
  }
}
4

2 に答える 2

0

そのためには、コードを次のように変更する必要があります ([arrayNo removeAllObjects] を使用して配列をクリアします)。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    if ([cell.textLabel.text isEqualToString: @"Arts and Museums"])
    {
      NSString *galleries = @"Art Galleries";
      NSString *dramatic = @"Dramatic Arts";
      NSString *museums = @"Museums";

      [arrayNo removeAllObjects];

      [arrayNo addObject:galleries];
      [arrayNo addObject:dramatic];
      [arrayNo addObject:museums];

      NSLog(@"LOADED");
      [self.myTableView reloadData];
  }
}
于 2013-05-01T02:19:14.790 に答える