How to launch a ViewController from a Non ViewController class?

后端 未结 7 1913
星月不相逢
星月不相逢 2020-12-22 09:48

the title says it all, i usually open ViewControllers like this

ListingViewController *listingView = [[ListingViewController alloc]init];
[self.navigationCon         


        
相关标签:
7条回答
  • 2020-12-22 10:34

    The usual way is to implement the UICollectionViewDelegate method – collectionView:didSelectItemAtIndexPath: in the view controller that contains the UICollectionView. Then you can present the new view controller in the normal way.

    For example:

    - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
        [collectionView deselectItemAtIndexPath:indexPath animated:YES];
    
        MyModel * model = self.listItems[indexPath.row]; //retrieve the object that is displayed by the cell at the selected index
    
        MyViewerViewController * vc = [[MyViewerViewController alloc] initWithMyModel:model];
        [self.navigationController pushViewController:vc animated:YES];
    
    }
    
    0 讨论(0)
提交回复
热议问题