私は、navigationController アプリケーションを作成しました。スタック内に、基本的に次のようなサブクラスがあります。
- rootViewController
- LeaderboardViewController <----- ファイル所有者に設定されたこの VC 内の UITableView
- UITableViewCell
- UICollectionView <----- これは、新しいビュー コントローラーをプッシュしようとしている場所です
- UITableViewCell
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
ました。NSNotificationCenter
postInfo
- (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];