0

私は、navigationController アプリケーションを作成しました。スタック内に、基本的に次のようなサブクラスがあります。

  • rootViewController
  • LeaderboardViewController <----- ファイル所有者に設定されたこの VC 内の UITableView
    • UITableViewCell
      • UICollectionView <----- これは、新しいビュー コントローラーをプッシュしようとしている場所です

UITableViewCell.m ファイルにある collectionView didSelect メソッド内:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    userCell *user = (userCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
    imageTag = ((UICollectionView *)user).tag;
    leaderboardViewController *leaderboardView = [[leaderboardViewController alloc] init];
    [imageManager getInsightWithCompletionBlock:^(UIImage *image){
          [leaderboardView postInfo];

    }];
}

次に、leaderBoardViewController.m に postInfo メソッドがあります。

-(void)postInfo
{
    NSLog(@"posted!");
    largeInsight *detailedInsight = [[largeInsight alloc] initWithNibName:@"largeInsight" bundle:[NSBundle mainBundle]];
    [[self navigationController] pushViewController:detailedInsight animated:YES];        
}

NSLog がデバッグ領域に表示されるため、postInfo 関数は実行されていますが、新しい viewController はプッシュされません。私はそれが私が逃したものであるか、私が想定されていないことをしていると推測しています... LeaderboardViewControllerを参照しているため、UICollectionViewサブクラスが原因ではないと思います。そのナビゲーションコントローラーのコードを実行していない理由がわかりません。誰かがこの同じ問題に遭遇しましたか? ありがとう!

アップデート

助けを借りて、新しいインスタンス変数を削除し、通知が送信されたときにメソッドを実行する VC を指すようにしleaderboardViewControllerました。NSNotificationCenterpostInfo

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    userCell *user = (userCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
    imageTag = ((UICollectionView *)user).tag;

    [imageManager getInsightWithCompletionBlock:^(UIImage *image){[[NSNotificationCenter defaultCenter] postNotificationName:@"PostCellInformation" object:self];
    }];
}

次に、collectionView が初期化される leadboardVC.m で:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(postInfo) name:@"PostCellInformation" object:nil];
4

1 に答える 1

1

この線...

leaderboardViewController *leaderboardView = [[leaderboardViewController alloc] init];

... の新しいインスタンスを作成しますleaderboardViewController。これは新しいため、表示を制御している現在のビュー コントローラー階層の一部ではありません。つまり、プッシュするものはすべて、現在の表示階層の一部でもありません。

(そのため、あなたも入っていると思いますnavigationControllernilpostInfoその値を確実にログに記録したいと思います。)

于 2012-12-05T13:17:53.440 に答える