Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Unrecognised selector sent to instance

I'm having problems with a tutorial I am watching on the UINavigationController and TableView.


The link is here:


http://www.youtube.com/watch?v=vY8tQQn4evo


Everybody seems to be saying, great, thanks, worked perfectly, etc. But everytime I try to implement about the first 10 mins of the video I get an unrecognised selector sent to instance 0x71788a0 to the UIViewController tableView: numberOfRowsInSection, which there clearly isn't a problem with as I've tried a new projects following the same proceedures.


I've tried relinking the table to files owner, all the usual troubleshootng tecniques and the same error is outputted. The only thing differerent to all my other practice/tutorial projects is the way the ViewController and UINavigationController get loaded into the UIWindow:



#import "AppDelegate.h"

#import "ViewController.h"



@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];

// Override point for customization after application launch.

UIViewController *viewController = [[UIViewControlleralloc] initWithNibName:@"ViewController"bundle:nil];

UINavigationController *navController = [[UINavigationControlleralloc]initWithRootViewController:viewController];

self.window.backgroundColor = [UIColorwhiteColor];

self.window.rootViewController = navController;

[self.windowmakeKeyAndVisible];

returnYES;

}

Posted on Apr 20, 2013 6:51 AM

Reply
Question marked as Best reply

Posted on Apr 20, 2013 8:05 AM

Are you sure your method is defined exactly like this:


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
...
...
...
}
20 replies

Apr 21, 2013 8:45 AM in response to xnav

xnav wrote:


Then you change that class from UIViewController to your own ViewController class.

This is done for the user via the 'New File...' dialog if the tutorial is followed. However, I agree, the OP should switch to the Apple tutorials and sample code.

I know of no way that "New File" will change the class of a UIViewController in Interface Builder. It sounds like the tutorial is trying to turn a UIViewController into a UITableViewController. If, for some strange reason, someone wanted to try to do that manually, they would have to change the class in Interface Builder from UIViewController to some derived class that responds to table view messages. This sure doesn't look like a tutorial that anyone needs to follow.

Apr 21, 2013 10:18 AM in response to xnav

Thanks for the feedback guys and apoligies if I seemed frustrated at the time, but this has taught me a valuable lesson as in follow apple tutorials rather than YouTube. I followed one of the guys tutorials on custom cells, and even though it worked, I had yellow lines under parts of the code, which did indicate that something was not 100%, which reinforces what you guys say 🙂


I managed to get hold of the IOS book Beggining IOS 6 Development by LaMarche, Mark, et al. that xnav recommended in a previous post so I will start on that asap.


Just to add to this sigbrt error, I did notice that the view (ViewController.xib) was hooked up to UITableView. I broke the connection and connected it to Files Owner, but still the same error.


Thanks

Apr 21, 2013 4:18 PM in response to xnav

xnav wrote:


When you add a VC with the 'New File...' dialog and have the xib box checked the xib will be created with the correct custom class of the VC.

Ah. I see. I think that speaks to a lot of the frustration new developers are finding. The iPhone architecture still evolving. There are a lot of cobbled-together practices that need to be re-evaluated. I was never interested in the iPhone and only wrote one app for the iPad. Getting a pop-over to display was crude.


With modern features like Storyboards, I don't think any of that is necessary. Apple continues to support all of those old practices but there is no need for new developers to trudge through that stuff. I'm getting back into it now and following Apple's latest, best practices and things are much easier than in 2010.


@Daz1761,

One thing that will really help if you go through Apple's official tutorials is to learn the correct terminology. When you say a view is "hooked up" do you mean the class name or one of the delegate pointers? I had the same problem with the user interface elements. If I hover over them, I can see the correct terminology is the Custom Class section of the Identity Inspector. That is one way to define a custom class in Interface Builder that would respond to those table view delegate methods. Unless you have a specific reason to do that, I think a UITableViewController would be better.

Unrecognised selector sent to instance

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.