简体   繁体   中英

Changing a Table View Controller to a View Controller

I have a Table View Controller that displays information using JSON. I want to change the styling of my app, and I don't want it to have that "table" view that it has now. Whats the easiest way to change my Table View Controller to a regular View Controller, the biggest problem I have is that the code uses a tableView and I dont know how to get it to work as a regular view controller.

I using a Storyboard with a TableViewController thats linked to a controller called UpcomingReleasesViewController.

I want my app: https://www.dropbox.com/s/ehs2vpsv3671s2j/Photo%20Sep%2003%2C%203%2015%2042%20PM.png

To look like this: https://www.dropbox.com/s/q5yfhrs4fr8uvvm/Photo%20Aug%2029%2C%201%2011%2035%20AM.png

My original answer was assuming you just wanted to convert from a UITableViewController to a UIViewController . Looking at your screen snapshots, I infer you really want to switch from a UITableViewController to a UICollectionViewController (which is an iOS 6 feature than allows you to do precisely what you want).

In that case, change your base class to UICollectionViewController , and replace your UITableViewDataSource methods with UICollectionViewDataSource methods. And then redesign your scene using a Collection View Controller.

See the Collection View Programming Guide for more information. Or see WWDC 2012 sessions Introducing Collection Views or Advanced Collection Views and Building Custom Layouts .

If you need to support iOS versions prior to 6, then you have to do this collection view style coding yourself manually, putting your image views on a scroll view and using a standard UIViewController . It require more effort than using a collection view, but can be done.


Original answer:

If this view controller will have a table view on it, but you just want to add more controls to the scene? If so, just change the view controller's base class from UITableViewController to UIViewController , create the new scene, add a table view to it, and specify the table view's delegate and data source to be the view controller:

在此输入图像描述

Also, make sure you define an IBOutlet for your table view (and if you call it tableView , that will minimize any coding changes needed).

在此输入图像描述

If you do that, you can quickly convert a UITableViewController based controller to a UIViewController with minimal code changes.

If you're looking to make something like your new UI mockup, look into UICollectionView . You'll see many of the same concepts (ie dataSource, delegate method signatures are similar) that are used in UITableViews used in the collectionView API.

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