09 Dec 2008, 22:46
Recent_3_pragsmall

Craig Williams (6 posts)

I am not sure what I am missing here. I went through the videos once and everything worked correctly. I started over to go through them a second time and I can’t get past the first part.

I have started from scratch five times and reinstalled Xcode just for good measure. Each time I get the same error:

bq. Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘*** -[UIApplication tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x520760’

Here is my .m file code:

#import "Recipe4ViewController.h"

@implementation Recipe4ViewController

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"recipeCell"];
	if(nil == cell) {
		cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"recipeCell"] autorelease];
	}
	if(indexPath.row == 0) {
		cell.text = @"Cherry Pie";
	} else if(indexPath.row == 1) {
		cell.text = @"Cake";
	} else if(indexPath.row == 2) {
		cell.text = @"Cookie";
	}
	return cell;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
	return 3;
}

and here is the .h file:

@interface Recipe4ViewController : UIViewController <UITableViewDataSource> {
}
@end

Thanks for any help.

Craig

10 Dec 2008, 12:17
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

Check what the datasource for you tableview is set to. Everything in your code looks fine so my guess is that the datasource is set to a different object.

Good luck!

10 Dec 2008, 15:19
Recent_3_pragsmall

Craig Williams (6 posts)

Thanks for following up Bill. So others may benefit from my mistake, here was the issue. I was putting the table view into the MainWindow.xib.

10 Dec 2008, 16:10
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

Hi Craig,

So you had your table view’s datasource connected to the files owner in the MainWindow.xib file? And the file’s owner is the UIApplicaiton which does not conform to the UITableViewDatasource protocol.

Thanks for following up!

09 Feb 2009, 10:19
Generic-user-small

Danish Najam (6 posts)

Hi Bill, I bought all your episodes. And they were really helpful in giving me Ramp up over iPhone Application Development. And by progressing through those I have got a slightly different version of the above problem.

I am creating Tab Bar Application using the template and in that I have attached the nib files in each of the Tab Bar item. Then Each of the view has been shown successfully.

Now I want to loads a table view in each of the tabs. I have created separate View Controller (VC) for each of the Tab and mentioned those VC name in each nib file’s File owner class attribute. So the File Owner Class = FirstViewController And from IB I have connected the datasource and delegates attributes of the view to my File Owner.

My View Controller declaration is below @interface FirstViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>

and I have implemented the required method in FirstViewController.m similar to below

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@”myCel”]; if(nil == cell) { cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@”myCel”] autorelease]; } cell.text = @”test”; return cell; }

  • (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section { return 1; }

  • (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@”cell clicked {%d, %d}}”, indexPath.row, indexPath.section); }

But I Keep on getting getting the exception * -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x407ba0 2009-02-09 03:01:45.159 Test[4285:20b] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘* -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x407ba0’

Now I request you to please help me about what I missed or went wrong in it. Regards –danishnajam

09 Feb 2009, 10:38
Generic-user-small

Danish Najam (6 posts)

Sorry Bill for bothering you. However it ended up being a connection problem in IB. I didn’t have each tab connected to a view controller. I only had them connected to the xib files. Lemme add a word for naive user like me that do connect your Tab Bar in the Main window xib to your custom view Controllers as well. Cheers –danishnajam

09 Feb 2009, 12:27
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

Hi Danish,

No problem at all, questions that get answered all by themselves are the easiest :)

Let us know when you get an app published!

26 May 2009, 20:34
Generic-user-small

Anthony Palomba (2 posts)

Hey Bill,

I am trying to get through episode 1 and have encountered the same problem that Craig originally found…

I followed the tutorial but when I build and run the app in the emulator, I get the following error.

2009-05-26 15:19:09.354 Recipes[3138:20b] cellForRowAtIndexPath: {0}} 2009-05-26 15:19:09.355 Recipes[3138:20b] * -[UITableViewCell initWithFrame:resuseIndentifier:]: unrecognized selector sent to instance 0x528ff0 2009-05-26 15:19:09.358 Recipes[3138:20b] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘* -[UITableViewCell initWithFrame:resuseIndentifier:]: unrecognized selector sent to instance 0x528ff0’

I downloaded the example source and confirmed that it matches mine. Any ideas what the problem might be?

Thanks, Anthony

26 May 2009, 20:59
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

Its just a typo in your code,

The method name you are sending is ‘initWithFrame:resuseIndentifier:’ and the proper method name is ‘initWithFrame:reuseIdentifier:’. You should have a warning from the compiler that ‘initWithFrame:reuseIndentifier:’ might not be implemented ( a yellow line in the code).

Hope this helps.

26 May 2009, 21:04
Generic-user-small

Anthony Palomba (2 posts)

Gah! Yes that was indeed the problem. Sorry to bother you for such a thing, I will look more closely next time.

27 May 2009, 02:12
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

No worries, happens to me all the time.

03 Jun 2009, 08:02
Generic-user-small

Giannandrea Castaldi (1 post)

Hi, I’ve the same problem of Danish with a Tab Bar Application with several xib files loaded in each tab. I’ve added a new tab with a table list and the owner’s file is a my extension of UITableViewController used as delegate and datasource from the table view and with outlet view to the table view. I’ve the following error: ` 2009-06-03 08:58:53.422 MyApp[628:20b] * Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘* -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x5270f0’ 2009-06-03 08:58:53.423 MyApp[628:20b] Stack: ( `

The solution should be in the message posted by Danish: “… it ended up being a connection problem in IB. I didn’t have each tab connected to a view controller. I only had them connected to the xib files. Lemme add a word for naive user like me that do connect your Tab Bar in the Main window xib to your custom view Controllers as well …”. I thought that if in the xib file loaded in the tab the owner’s file is the correct controller for the referenced view all is ok but now seems that I must connect the tab of the MainWindow.xib to the controller, how can I connect them with IB if they are in different xib files? Can you explain me step by step how make it? Thanks.

Giannandrea

03 Jun 2009, 10:31
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

The error message says that an instance of ‘UIViewController’ was sent the message ‘tableView:numberOfRowsInSection:’. That method is part of the table view data source protocol. So my guess is you have a connection from a table view to a ‘File’s Owner’ object that has had its class set to your particular view controller. But the real instance, created in another nib file, has not had its class set.

Check each nib file to make sure all the view controllers have their class set properly.

Good luck.

06 Aug 2009, 17:22
Picture_3_09-23-14_pragsmall

Jeremy W. (20 posts)

Hi, just wanted to contribute, I was a little confused. I have the same tab based app that Danish Najam has along with the same error, so I ended up here :)

To make this easier, I will explain my app a little. I have a tab bar, it contains 3 icons (contact, activities & history). I created my application using the xcode template for tab app. Like it suggested I created a separate “MainView” for my contacts so each “entitiy” has it own view.XIB. I then created classes for each controler ie. ContactViewControler.

The part that I was confused on was apparently you have to specify the class (ContactViewControler) in two places 1. on the file’s owner in the ContactView.xib set the class to ContactViewControler, and specify three link ( ContactView.xib)File Owner’s “View” to TableView TableView’s “Delagate” to File Owner ( ContactView.xib) TableView’s “Datasource” to File Owner( ContactView.xib) 2. in the MainWindow.xib open Tab Bar Controller, click the contact tab bar button Set its class to ContactViewControler. Also Set its NIB Name to ContactView.xib.

Once I did this all my error went away, luck I had no code issues.

I say all of this to ask, why do we have to specify the controler class twice. more specifically why does the tab bar care, should the NIB file we load take care of all of that and the tab bar is merely a short cut or link to the ContactsView?

Just looking for some clarification, and logical reasoning. Jeremy

07 Aug 2009, 18:53
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

Hi Jeremy,

The ‘File’s Owner’ is not an object, its a proxy. The real object lives in the other nib file. There is where you must set the class. You can leave ‘File’s Owner’s class as NSObject if you want and it would still load. However, the view outlet must be set on a view controller. For the files’ owner to know that it has a view you must set the class to something deeper in the hierarchy than NSObject (namely at least UIViewController). If you want IB to know about your specific outlets then of course you must tell it the file’s owner is of your class.

Another source of info on the files owner is the documentation on the ADC site in the discussion of nib files.

Good luck, and I hope this helps.

29 Aug 2009, 01:55
Generic-user-small

Andrew Hall (2 posts)

Hi Bill, Guess I’m having a similar problem, but I can’t seem to use the information above to fix it…so here is my problem:

I’m trying to draw various polygon shapes in a UIView. I have the following method defined in my PolygonShapeView.h:

  • (NSArray *)pointsForPolygonInRect:(CGRect)rect numberOfSides:(int)numberOfSides;

and in my PolygonShapeView.m file, in my - (void)drawRect:(CGRect)rect method, I message above method as follows:

NSArray *points = [self pointsForPolygonInRect:[self frame] numberOfSides:numberOfSides];

When I do, I get the following logged to the debugger console: . . 2009-08-28 18:48:34.584 HelloPoly[737:20b] I’ve entered the drawRect method call in PolygonShapeView.m 2009-08-28 18:48:34.584 HelloPoly[737:20b] * -[PolygonShapeView pointsForPolygonInRect:numberOfSides:]: unrecognized selector sent to instance 0xd26f30 2009-08-28 18:48:34.585 HelloPoly[737:20b] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘* -[PolygonShapeView pointsForPolygonInRect:numberOfSides:]: unrecognized selector sent to instance 0xd26f30’ 2009-08-28 18:48:34.585 HelloPoly[737:20b] Stack: (

and I get my yellow warning in Xcode.

I can’t see that i’ve got typos in the method call. I’ve tried to follow the IB discussions above. My PolygonShapeView view is connected to my controller as a Referencing Outlet, my File’s Owner class is UIApplication with a class outlet to my system defined delegate.

I can’t seem to get a handle on what’s wrong with the selector and why it isn’t recognized. My Xcode warning is that my PolygonShapeView class object may not respond to ‘-pointsForPolygonInRect:numberOfSides:’

Any time and help is much appreciated.

01 Sep 2009, 10:54
Biopic_100x100_pragsmall

Bill Dudney (917 posts)

Hi Andrew,

Sorry to be late to respond.

It looks to me like you are sending a class method (the + at the front of the method is what makes it a class method) to an instance.

Instead of [self pointsForPolygonInRect:numberOfSides:] you have to send this message to the class with [[self class] pointsForPolygonInRect:numberOfSides:]. Or you can make that method an instance method (but that seems wrong given the name of the method).

Hope this helps!

06 Sep 2009, 02:59
Generic-user-small

Andrew Hall (2 posts)

Bill, Thanks very much. That was it. Mixing up the class method definition with an instance receiver. I really appreciate the help. Your explanations are simple for a newbie like me to follow and right on target.

Thanks again!

07 Feb 2011, 03:33
Generic-user-small

David Whitehurst (4 posts)

I am receiving the following error and I’m finding that many things can cause this error. I think it’s something in IB. I’m not really sure. Here’s the console output:

[Session started at 2011-02-06 22:18:21 -0500.] 2011-02-06 22:18:26.297 Punch[34634:207] Selected punch object: Projects 2011-02-06 22:18:26.301 Punch[34634:207] -[NSPlaceholderArray arrayWithObjects:]: unrecognized selector sent to instance 0x4d13470 2011-02-06 22:18:26.304 Punch[34634:207] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘-[__NSPlaceholderArray arrayWithObjects:]: unrecognized selector sent to instance 0x4d13470’ *** Call stack at first throw: ( 0 CoreFoundation 0x00f8ebe9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x010e35c2 objc_exception_throw + 47 2 CoreFoundation 0x00f906fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x00f00366 __forwarding + 966 4 CoreFoundation 0x00efff22 _CF_forwarding_prep_0 + 50 5 Punch 0x00004548 -[ProjectController viewDidLoad] + 184 6 UIKit 0x0036e65e -[UIViewController view] + 179 7 UIKit 0x0036ca57 -[UIViewController contentScrollView] + 42 8 UIKit 0x0037d201 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48 9 UIKit 0x0037b831 -[UINavigationController _layoutViewController:] + 43 10 UIKit 0x0037ca86 -[UINavigationController _startTransition:fromViewController:toViewController:] + 326 11 UIKit 0x00377606 -[UINavigationController _startDeferredTransitionIfNeeded] + 266 12 UIKit 0x0037e83e -[UINavigationController pushViewController:transition:forceImmediate:] + 932 13 UIKit 0x003774a0 -[UINavigationController pushViewController:animated:] + 62 14 UIKit 0x00336794 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140 15 UIKit 0x0032cd50 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219 16 Foundation 0x0003f7f6 NSFireDelayedPerform + 441 17 CoreFoundation 0x00f6ffe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 19 18 CoreFoundation 0x00f71594 __CFRunLoopDoTimer + 1220 19 CoreFoundation 0x00ecdcc9 __CFRunLoopRun + 1817 20 CoreFoundation 0x00ecd240 CFRunLoopRunSpecific + 208 21 CoreFoundation 0x00ecd161 CFRunLoopRunInMode + 97 22 GraphicsServices 0x018c3268 GSEventRunModal + 217 23 GraphicsServices 0x018c332d GSEventRun + 115 24 UIKit 0x002cf42e UIApplicationMain + 1160 25 Punch 0x00002896 main + 84 26 Punch 0x00002839 start + 53 ) terminate called after throwing an instance of ‘NSException’

My method is here in RootViewController:

  • (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // select static row and view controller Punch *obj = [self.punchList punchAtIndex:indexPath.row]; NSLog(@”Selected punch object: %@”, obj.name);

    if (0 == indexPath.row) { self.projectController.key = @”project”; self.projectController.title = @”Projects”; }

    [self.navigationController pushViewController:projectController animated:YES]; }

My design is as follows:

I started with an iPad split-view template and then I replaced the RootViewController popOver with a UINavigationController. I also created a separate RootViewController.xib file with a TableView. I select “Projects” and then bomb with the above error. I was loading the RootViewController’s view with Objects.name in the cells. I simplified this table with strings in an NSArray. I thought that the Punch object in the View (e.g. punch.name) was really not a String. The NSLog works and I see the String selected.

I’m really stumped.

Thanks for any help folks.

07 Feb 2011, 05:13
Generic-user-small

David Whitehurst (4 posts)

I solved my problem partially. I solved the problem where I select from the RootViewController view and now my SecondLevelController is placed on the stack and instantiated. The problem is that I used data from the iPhone SDK book where “key” is used for DVDCabinetController. I want to use this setup so that I can pull from the database a list of “Projects”,”Applications”, and “Products” from the root view.

I commented out all the array and dictionary stuff and the selector issue went away. It was because “key” is not recognized or set I don’t think. Not sure:

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	// select static row and view controller
	//Punch *obj = [self.punchList punchAtIndex:indexPath.row];
	//NSLog(@"Selected punch object: %@", obj.name);

	if (0 == indexPath.row) {
		
		[self.projectController setKey:@"project"];
		self.projectController.title = @"Projects";
	}
	
	projectController = [[ProjectController alloc] initWithNibName:@"ProjectController" bundle:nil];
	[self.navigationController pushViewController:projectController animated:YES];
	[projectController release];	

}

</code>

And the projectController code:

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
 - (void)viewDidLoad {
	 arrayData = [[NSArray alloc] initWithObjects:@"Project-1",@"Project-2",@"Project-3",@"Project-4",@"Project-5",nil];
	 [super viewDidLoad];
	 self.title = @"Project";
	 
	 // keys
	 //NSArray *keys = [NSArray arrayWithObjects:@"project",@"application",@"product",nil];

	 // arrays for each selection
	 //NSArray *projectOBJs = [NSArray arrayWithObjects:@"Project-DLW1",@"Project-DLW2",nil];
	 //NSArray *applicationOBJs = [NSArray arrayWithObjects:@"Application-DLW10",@"Application-DLW20",nil];
	 //NSArray *productOBJs = [NSArray arrayWithObjects:@"Product-DLW100",@"Product-DLW200",nil];

	 // array of arrays
	 //NSArray *values = [NSArray arrayWithObjects:projectOBJs, applicationOBJs, productOBJs, nil];
	 
	 // data holds keys and values
	 //data = [[NSDictionary alloc] initWithObjects:values forKeys:keys];
	 
 }

</code>

The fixed array works but use of “key” gives the selector error. I haven’t brought in the data model yet so that’s why I’m just looking for good design. I like the concept of calling the projectController maybe SecondaryViewController and switching on “key” or similar.

Can anyone explain why I get a selector error?

Thanks in advance,

David

  You must be logged in to comment