Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

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

Reply
 
LinkBack Thread Tools Display Modes
Old 05-11-2011, 12:46 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 54
bebus77 is on a distinguished road
Default UITableView in each tab

hello,

I'm currently developing a tab bar based application with 5 tabs that have an UITableView each. Each tab is linked to a normal UIViewController, the first two with the ones that xCode creates by default and the others with the ones I created.
If I try to add a table view to the first two view controllers (default ones) everything works smoothly, but when I do the same with the others, the app crashes telling me that:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x4e2f6f0'

and the tableView:numberOfRowsInSection: in my .m file is this (i'm implementing proper delegates in the .h):

Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}
do you know any solution ? I've looked around with no result

thanks in advance for answers
bebus77 is offline   Reply With Quote
Old 05-11-2011, 01:14 PM   #2 (permalink)
Registered Member
 
Join Date: Oct 2010
Location: Atlanta, GA
Posts: 148
tripp13 is on a distinguished road
Default

Quote:
Originally Posted by bebus77 View Post
hello,

I'm currently developing a tab bar based application with 5 tabs that have an UITableView each. Each tab is linked to a normal UIViewController, the first two with the ones that xCode creates by default and the others with the ones I created.
If I try to add a table view to the first two view controllers (default ones) everything works smoothly, but when I do the same with the others, the app crashes telling me that:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x4e2f6f0'

and the tableView:numberOfRowsInSection: in my .m file is this (i'm implementing proper delegates in the .h):

Code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}
do you know any solution ? I've looked around with no result

thanks in advance for answers
have you declared the tableviews in your .h files and have you connected them in IB? It sounds like the tableview's have not been declared.
tripp13 is offline   Reply With Quote
Old 05-11-2011, 01:23 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 54
bebus77 is on a distinguished road
Default

yep, I've declared it and connected it, but usually you don't even have to do this. It looks pretty strange, any other suggestion ?

thanks
bebus77 is offline   Reply With Quote
Old 05-12-2011, 08:02 AM   #4 (permalink)
Registered Member
 
Join Date: Oct 2010
Location: Atlanta, GA
Posts: 148
tripp13 is on a distinguished road
Default

Quote:
Originally Posted by bebus77 View Post
yep, I've declared it and connected it, but usually you don't even have to do this. It looks pretty strange, any other suggestion ?

thanks
How did you setup the tableViews in the first two "default" views? The warning is telling you that UIViewController is receiving an unrecognized selector. This is a tableView method so it would be a fault I believe. If all four viewControllers are just UIViewController's check how the first two implement the tableView you added. Look in their viewDidLoad methods as well to see how the tableView's are loaded.

That's all I can think of right now.
tripp13 is offline   Reply With Quote
Old 05-12-2011, 08:15 AM   #5 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 54
bebus77 is on a distinguished road
Default

in the viewDidLoad methods there is nothing in every class as I'm just testing for now. To implement the UITableViews I use the standard methods:

Code:
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
	
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}
I've used this code in many other UIViewControllers of many projects, I think it's something related to the TabBar which make these new controllers work strange.
bebus77 is offline   Reply With Quote
Old 05-12-2011, 09:22 AM   #6 (permalink)
Registered Member
 
Join Date: Oct 2010
Location: Atlanta, GA
Posts: 148
tripp13 is on a distinguished road
Default

Quote:
Originally Posted by bebus77 View Post
in the viewDidLoad methods there is nothing in every class as I'm just testing for now. To implement the UITableViews I use the standard methods:

Code:
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
	
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}
I've used this code in many other UIViewControllers of many projects, I think it's something related to the TabBar which make these new controllers work strange.

Alright. We'll get this worked out. Did you add the delegate and data source to your .h files for your new viewControllers? Is the entire view a tableView, or is it just a meant to be a small portion of your view?

I'm at work, so I can't step through any codes and duplicate what you have yourself. Let's keep trying to solve this, but I can work it out and follow along later today when I get home...I'm on the east coast of the United States (GMT -0500 hrs) and it is 10:18 AM (1018 hrs) right now. I'll be home around 5:30 PM (1730 hrs) and can get more in depth.

Keep tyring and let me know how it's going in the mean time and I'll come up with more ideas with each post.
tripp13 is offline   Reply With Quote
Old 05-12-2011, 09:37 AM   #7 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 1,106
Meredi86 is on a distinguished road
Default

It sounds as though you have not declared in your .h what you need to. though with 2 working i would be surprised if you had missed this. Worth a suggestion to discount it anyway:

Code:
@interface ClassName : UIViewController <UITableViewDelegate, UITableViewDataSource> {
I know it sounds and is a very simple possible solution, but youd be surprised how often little things like this can crop up when working on too much code or going through it too quickly.

Hope this helps. Ill also keep an eye on this thread and see if i can lend the little bit of wisdom i sometimes manage to come across.
Meredi86 is offline   Reply With Quote
Old 05-12-2011, 11:56 AM   #8 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 54
bebus77 is on a distinguished road
Default

yep I have those delegates in my .h file, I'm sure it's something connected to the tab bar as I often do this kind of process and it always works smoothly
bebus77 is offline   Reply With Quote
Old 05-12-2011, 02:06 PM   #9 (permalink)
Registered Member
 
Join Date: Oct 2010
Location: Atlanta, GA
Posts: 148
tripp13 is on a distinguished road
Default

Quote:
Originally Posted by bebus77 View Post
yep I have those delegates in my .h file, I'm sure it's something connected to the tab bar as I often do this kind of process and it always works smoothly
in IB, have you changed the properties in the drop down menu's? I can't remember where they're located right now, but will check in a bit.

also, try adding your tableViews to your viewDidLoad method like this:

Code:
[view addSubview:tableView];
It's this part of the warning
Code:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x4e2f6f0'
that causes me to believe it's because your UIViewController is not implementing your tableViews and is treating your tableViews as though they are not there.

if you could, post your .h and .m files for your viewcontroller 3.
tripp13 is offline   Reply With Quote
Old 05-18-2011, 10:59 AM   #10 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 54
bebus77 is on a distinguished road
Default

sorry for the delay and thanks for the answers, these are the files:

Code:
#import <UIKit/UIKit.h>


@interface MusicView : UIViewController <UITableViewDataSource, UITableViewDelegate> {
    IBOutlet UITableView *tv;
}

@end
Code:
#import "MusicView.h"


@implementation MusicView

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    //cell.textLabel.text = [elements objectAtIndex:indexPath.row];
	
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
bebus77 is offline   Reply With Quote
Old 05-27-2011, 12:39 PM   #11 (permalink)
Registered Member
 
Join Date: Oct 2010
Location: Atlanta, GA
Posts: 148
tripp13 is on a distinguished road
Default

Quote:
Originally Posted by bebus77 View Post
sorry for the delay and thanks for the answers, these are the files:

Code:
#import <UIKit/UIKit.h>


@interface MusicView : UIViewController <UITableViewDataSource, UITableViewDelegate> {
    IBOutlet UITableView *tv;
}

@end
Code:
#import "MusicView.h"


@implementation MusicView

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    //cell.textLabel.text = [elements objectAtIndex:indexPath.row];
	
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
add the bold print to below:
Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
[view addSubview:tvc];
}
Since you're using a UIViewController and not a UITableViewController, you need to add the tableview as a subview. UIViewController does not include those methods. You will have to alloc init the tableView as well. I think that will do the trick.

sorry for my delay getting back to you.
tripp13 is offline   Reply With Quote
Old 12-25-2011, 03:55 PM   #12 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 4
MrWaqasAhmed is on a distinguished road
Default

I might be late , but i think ppl who get this error might take advantage of this answer , anyways the solution is that

"click on the tab bar item in iterface buildder , which you have added (i.e not first two tabs) then go to indentity inspector , change the Class from UITableViewController or watever it would be to your view which you want to show up on this tab" . Thats work for me .

Regards
Waqas Ahmed
MrWaqasAhmed is offline   Reply With Quote
Old 12-25-2011, 07:05 PM   #13 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by tripp13 View Post
add the bold print to below:
Code:
- (void)viewDidLoad
{
    [super viewDidLoad];
[view addSubview:tvc];
}
Since you're using a UIViewController and not a UITableViewController, you need to add the tableview as a subview. UIViewController does not include those methods. You will have to alloc init the tableView as well. I think that will do the trick.

sorry for my delay getting back to you.
You only need to add the table view as a subview in code if you don't set it up that way in IB. I almost always hook up the table view to the view controller in IB, so the code you say to add is not needed.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 12-25-2011, 07:07 PM   #14 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by MrWaqasAhmed View Post
I might be late , but i think ppl who get this error might take advantage of this answer , anyways the solution is that

"click on the tab bar item in iterface buildder , which you have added (i.e not first two tabs) then go to indentity inspector , change the Class from UITableViewController or watever it would be to your view which you want to show up on this tab" . Thats work for me .

Regards
Waqas Ahmed
Makes sense. It sounds like the Apple template expects all the tabs in the tab bar controller to point to UITableViewController objects. They are a special subclass of UIViewController that has table view support built into it. In your case, you are using a generic view controller and adding the delegate and data source methods yourself. That's what I usually do. I don't find the UITableViewController class very useful.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone, objective-c, sdk, tabs, uitableview

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



» Advertisements
» Online Users: 358
7 members and 351 guests
doffing81, dre, iOS.Lover, Kirkout, MikaelBartlett, oztemel, PlutoPrime
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:02 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0