简体   繁体   中英

Xcode universal application with one storyboard

How can we make a universal application in Xcode so that if the iPhone view has a table view the iPad has a collection view? I can't think of how we can do this using size classes.

This is how I would do it.

  • Add both UITableView and UICollectionView to your "one" universal story board.
  • Connect UITableView and UICollectionView using IBOutlets.
  • Add both delegates to your *.h file
  • Add delegate code for both views in *.m file.
  • Use an if/else clause to see what device is running your app and depending upon the answer hide the view.

     if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { //its iphone, hide UICollectionView //ie myCollectView.hidden=YES; } else { //its ipad, hide UITableView //ie mytableView.hidden=YES; } 

您应该选择尺寸分类和自动布局。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM