Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Dave Thomas
Dave Thomas
2,555 Points

Can I create a TableViewController that is not full screen?

I am able to build the blog reader app and have an app in mind using table views that do not use full screen. I have tried dropping a table view into a view but I can't get my table view to connect to my custom class (it does not show up in the custom class chooser and I can't type it in) and I can't drop a TableViewController into a view.

4 Answers

Stone Preston
Stone Preston
42,016 Points

sorry, just saw your title mentions you are using a tableView controller class, not a tableView class

yes you can use a custom class with a tableView inside a view controller but it needs to inherit from UITableView, not UITableView controller. your class probably inherits from a tableViewController which is why you cant set it as your tableViews class.

what you can do is just add a tableView to the view controller. you dont need to make a subclass. then connect the tableView as an outlet to your viewController. then you can just use the view controller as the controller for your tableView as well and copy and paste the blog reader code into your view controller class. you would need to make some changes but it should not be too hard to get working.

your view controller would need to conform to the tableView delegate protocol and you would need to set the table views delegate as the view controller. then implement the tableView delegate methods which you probably already have in there since you copied and pasted. there may be some other stuff you have to change.

Stone Preston
Stone Preston
42,016 Points

yes you should be able to drop a tableView into a ViewController and then set that tableViews class to your custom class. If it doesnt show up in the drop down just type the name of the class in manually and it should work. Sometimes cleaning your build fixes that problem when it doesnt show up in the class drop down so you can try that first and see if it comes up. if not jus type it in

Dave Thomas
Dave Thomas
2,555 Points

Not working...

  • Created the project (empty application)
  • Added MainStoryboard
  • Added a view with a label (Hello World Label and run, worked fine and could see everything)
  • created the custom class (basically copied from the blog reader tutorial)
  • added a tableView to the storyboard below the hello world label
  • added a tableViewCell
  • my custom class is not in the drop down and when I type it in it makes an error noise...
Dave Thomas
Dave Thomas
2,555 Points

Perfect,

with your instructions I added to the .h file

<UITableViewDelegate, UITableViewDataSource>

and the .m file in the viewDidLoad

[self.TableView setDelegate:self]; [self.TableView setDataSource:self];

and was able to get it working after a couple of google searches, Thanks!

Stone Preston
Stone Preston
42,016 Points

awesome glad you got it working