Go Back   iPhone Dev SDK Forum > Development Forums > iPhone SDK Development

Featured Member Applications

TanZen ($0.99)

Endless Walls ($0.99)

Air Hockey ($0.99)

SUPER STRIKE - Motion Bowl ($0.99)

BarSlot ($0.99)

MeterRead ($0.99)

Colorblind Helper ($4.99)

gContacts ($1.99)

ProgCalc ($1.99)

Forex On The Go Lite (FREE)

HUE knewit! ($0.99)

Want your application to be advertised here?

» Advertisements


Visit our friends over at The App Show! Steve and Dave produce a weekly show shining a light on the iPhone 2.0 software and the applications being developed by the amazing development community for the iPhone SDK!
» Online Users: 121
15 members and 106 guests
ammon, dicklacara, dtochetto, jclardy, johnqh, keyboardcowboy, MDMstudios, NewiPhoneDeveloper, rames44, RickMaddy, smstromb, snatch, solomon71, storm, wynodir
Most users ever online was 207, 10-24-2008 at 09:29 AM.
» Stats
Members: 3,913
Threads: 5,612
Posts: 23,248
Top Poster: scottiphone (705)
Welcome to our newest member, dtochetto
Reply
 
LinkBack Thread Tools Display Modes
Old 08-29-2008, 10:54 AM   #1 (permalink)
Junior Member
 
Join Date: Aug 2008
Posts: 17
Question Problem Creating a TableView in a TabBar App

Hey everyone, I'm at my wits end with this, and hopefully someone can help. I think this must be an Interface Builder bug, but let me know what you think and if you know a way around it.

Whenever I try to create a View in a tab bar based application that contains a Table View, I end up with the following exception when trying to switch to the tab:
'NSUnknownKeyException', reason: '[<UIViewController 0x451100> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.'

If I create a simple view based application with a Table View, everything works fine. I'll show the steps I go through below for both cases and hopefully someone can see what I'm doing wrong/differently that I don't realize.

Case 1:
  1. In Xcode go to File...New Project...View Based Application, and name it Demo.
  2. Open DemoViewController.h and add the following code in the appropriate two locations:
    Code:
    IBOutlet UITableView *tableView;
    @property (nonamtomic,retain) UITableView *tableView;
  3. Open DemoViewController.m and add the following line:
    Code:
    @synthesize tableView;
  4. Open DemoViewController.xib
    • Drag a Table View into the view
    • Right click on the table view.
    • Drag from the dot beside New Referencing Outlet to File's Owner and select tableView.
  5. Save everything and Build and Go. The table view shows up fine in the simulator.

Case 2:
  1. In Xcode go to File... New Project ... Tab Bar Application and name it Demo2.
  2. Right click on Classes...Add...New File...UIViewController subclass and name it SecondViewController.
  3. Open SecondViewController.h and add the following code in the appropriate two locations:
    Code:
    IBOutlet UITableView *tableView;
    @property (nonamtomic,retain) UITableView *tableView;
  4. Open SecondViewController.m and add the following line:
    Code:
    @synthesize tableView;
  5. Open SecondView.xib
    • Remove the label that says Second View
    • Select File's Owner and in the Inspector Identity tab change the Class to SecondViewController.
    • Drag a Table View into the view
    • Right click on the table view.
    • Drag from the dot beside New Referencing Outlet to File's Owner and select tableView.
  6. Save everything and Build and Go.
The first view shows up fine. Click on the Second tab. The simulator crashes with the following stack trace on the console:

[Session started at 2008-08-29 08:10:45 -0600.]
Loading program into debugger…
Warning - No location found for "DatabaseSearchViewController.m:53"
GNU gdb 6.3.50-20050815 (Apple version gdb-960) (Sun May 18 18:38:33 UTC 2008)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "i386-apple-darwin".warning: Unable to read symbols for "/System/Library/Frameworks/UIKit.framework/UIKit" (file not found).
warning: Unable to read symbols from "UIKit" (not yet mapped into memory).
Program loaded.
sharedlibrary apply-load-rules all
Attaching to program: `/Users/myusername/Library/Application Support/iPhone Simulator/User/Applications/662568B1-441A-4705-9003-0BF0D68D45C1/Demo2.app/Demo2', process 64174.
2008-08-29 08:10:50.011 Demo2[64174:20b] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x451100> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.'
2008-08-29 08:10:50.012 Demo2[64174:20b] Stack: (
2535018827,
2522071291,
2535017585,
2490358200,
2490356766,
2490899809,
818073927,
2534972549,
818068629,
818076920,
816648466,
816648934,
816688492,
816684429,
816177758,
818091155,
816177758,
816558114,
816559338,
816558227,
816177758,
816558114,
816559338,
816556080,

816274443,
816209415,
816206378,
829003042,
829012108,
2534520341,
2534522104,
829005112,
829005309,
816175835,
816221412,
9864,
9718
)
bhil is offline   Reply With Quote
Old 08-30-2008, 07:47 AM   #2 (permalink)
Member
 
Join Date: Aug 2008
Posts: 73
Default

You are missing a few steps here. I think your main mistake is this:
"Right click on Classes...Add...New File...UIViewController subclass and name it SecondViewController."
You should be adding a new UITableViewController subclass instead. It has a tableView field already and it is automatically hooked up to the first table in the xib you don't need to hook it up. You do however need to connect the delegate and the data source to the file's owner in the xib, and of course connect the file owner's view to the table .

Watch my video carefully which has 2 tables in a tab bar.
indiekiduk is offline   Reply With Quote
Old 08-30-2008, 10:29 PM   #3 (permalink)
Junior Member
 
Join Date: Aug 2008
Posts: 17
Default

Quote:
Originally Posted by indiekiduk View Post
You are missing a few steps here. I think your main mistake is this:
"Right click on Classes...Add...New File...UIViewController subclass and name it SecondViewController."
You should be adding a new UITableViewController subclass instead. It has a tableView field already and it is automatically hooked up to the first table in the xib you don't need to hook it up. You do however need to connect the delegate and the data source to the file's owner in the xib, and of course connect the file owner's view to the table .

Watch my video carefully which has 2 tables in a tab bar.
Thanks, this helped. I left the datasource and delegate out of the example because they were irrelevant to showing the exception. Following your example I can make things work, but I'm still not sure why the other way doesn't work. In my first example I am using a UIViewController and it works so why can't I do it in the second example?

More specifically, following your way only seems to work if the entire view is a table. I want a view in the second tab that has a search bar at the top, with a table taking the rest of the view and the only way IB lets me do that is if I am using a UIView, not a UITableView as the base view, and if I do that, I get errors saying the controller is expecting a UITableView. The only way to get rid of the errors is to switch the controller to a UIViewController (instead of UITableViewController as you suggest), which puts me right back at the spot I was in for my second demo.

I'm sure there's an easy way to do what I want, it just escapes me what it is. Is there a way to add another object to IB that I can connect my table view to? So I could have a UIViewController as the File's Owner, being the delegate and outlet for the search view, and then a second object that is a UITableViewController that is the delegate, datasource and outlet for the UITableView? Or am I trying to make things too complicated?
bhil is offline   Reply With Quote
Old 08-31-2008, 07:11 PM   #4 (permalink)
Junior Member
 
Join Date: Aug 2008
Posts: 17
Default

Well, I have things working the way I want them, but I'm not entirely sure why. After doing more research and looking into the TableSearch example, I found that it appeared they did exactly what I did in Case 2 of my original post, except including a UISearchBar as well. I repeated essentially what I did in Case 2, and this time it worked. I obviously did something different, but I'm not entirely sure what (and no, I did not use a UITableViewController anywhere).

Since I don't really have the time to keep repeatedly trying this over and over to find out what I did different, my test project instantly got promoted to a production project and I will deal with what was different the next time I need a search bar and table view together again.
bhil is offline   Reply With Quote
Old 09-02-2008, 10:43 PM   #5 (permalink)
Junior Member
 
Join Date: Sep 2008
Posts: 8
Default

I spent hours dealing with this as well and this post was the first Google result. Anyway, for anyone else's reference, see Apple - Support - Discussions - Very basic problem with Tab Bar ... for solution.

In short:
Beside naming/locate the nib file, you must also set the class in the view inside the tab bar.
amirbudicecep is offline   Reply With Quote
Old 09-03-2008, 10:03 AM   #6 (permalink)
Junior Member
 
Join Date: Aug 2008
Posts: 17
Default

Quote:
Originally Posted by amirbudicecep View Post
I spent hours dealing with this as well and this post was the first Google result. Anyway, for anyone else's reference, see Apple - Support - Discussions - Very basic problem with Tab Bar ... for solution.

In short:
Beside naming/locate the nib file, you must also set the class in the view inside the tab bar.
Fantastic find! I just tested this with my test case and it worked first try. In my vast fiddling I must have set this without realizing it to get my code working. I'm glad I can now consistently add tables to tab bars.

Thank you!
bhil is offline   Reply With Quote
Old 09-05-2008, 01:47 AM   #7 (permalink)
Junior Member
 
Join Date: Sep 2008
Posts: 14
Default

nice video, but now i am stuck again =(

in the FirstViewController.m

how do you access the navigation controller?

I want to push in another view,

but not sure how to access the navigation controller
to use the method pushViewController

thanks

sorry, totally new to iphone sdk =(
rapidbunny is offline   Reply With Quote
Old 09-05-2008, 03:13 AM   #8 (permalink)
Junior Member
 
Join Date: Aug 2008
Posts: 13
Default

Hi indiekiduk, thanks. It's helpful for me.
I have created two tab with table view. But i got a problem to add a table item. In the first table view i added simply "Hello Universe" it's working. Then i added NSMutableArray on second table view. but now its not working*

FirstViewController.m - [cell setText:@"Hello Universe"] - it's working fine..

but if add NSArray to AppDelegate it's not working. did anything wrong in this??

TabDemoAppDelegate.m - array = [[NSArray arrayWithObject:@"First",@"Second",@"Third",nil] retain]
dhanasekar is offline   Reply With Quote
Old 09-05-2008, 09:26 AM   #9 (permalink)
Junior Member
 
Join Date: Aug 2008
Posts: 17
Default

Quote:
Originally Posted by rapidbunny View Post
nice video, but now i am stuck again =(

in the FirstViewController.m

how do you access the navigation controller?

I want to push in another view,

but not sure how to access the navigation controller
to use the method pushViewController

thanks

sorry, totally new to iphone sdk =(
To access the navigation controller, you have to declare an IBOutlet for it in your controller class and connect it via IB the same way you connect any other outlet. Then you have direct access to it.
bhil is offline   Reply With Quote
Old 09-05-2008, 09:31 AM   #10 (permalink)
Junior Member
 
Join Date: Aug 2008
Posts: 17
Default

Quote:
Originally Posted by dhanasekar View Post
Hi indiekiduk, thanks. It's helpful for me.
I have created two tab with table view. But i got a problem to add a table item. In the first table view i added simply "Hello Universe" it's working. Then i added NSMutableArray on second table view. but now its not working*

FirstViewController.m - [cell setText:@"Hello Universe"] - it's working fine..

but if add NSArray to AppDelegate it's not working. did anything wrong in this??

TabDemoAppDelegate.m - array = [[NSArray arrayWithObject:@"First",@"Second",@"Third",nil] retain]
You haven't provided a lot of information here but going from what you have posted, you need to have the array declared in your table view's data source, and set the cell text from the appropriate location in the array in the method
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
bhil is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Powered by vBadvanced CMPS v3.0.1

All times are GMT -5. The time now is 03:32 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0