1

I'm writing this code and It keeps giving me this error. I have another project with the same code that doesn't give me the error, so I don't see what the problem is. The output is 2012-10-19 20:48:22.266 ScienceReader[5992:c07] -[UIView numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x74385f0 2012-10-19 20:48:22.268 ScienceReader[5992:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x74385f0' *** First throw call stack: The line in the debug session is return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); And the code in Viewcontroller.m is data = [[NSMutableArray alloc] initWithObjects:@"Delta", nil];

Nick Scottman
  • 3,289
  • 2
  • 14
  • 8
  • How do you set up the `UIPickerViewDataSource`? The error is claiming that the data source is a simple UIView that (quite reaonably) doesn't have a `numberOfComponentsInPickerView:` method. The problem with the line it's going to when debugging is due to a bad default in Xcode as shipped. Go into the Breakpoint Navigator and set a breakpoint on Objective-C exceptions to get better information when an error is encountered. – Phillip Mills Oct 20 '12 at 00:57
  • i put breakpoints in. I have a `numberOfComponentsInPickerView` method it has `return 1;` in it – Nick Scottman Oct 20 '12 at 01:01
  • It seems as though the object with that method is not the object assigned as the data source. It thinks that its data source is a `UIView`. – Phillip Mills Oct 20 '12 at 01:03
  • Since you're not providing any information about how you currently create and assign the data source, it's hard to give you specifics in return...but, basically, make sure that the object that implements that method is the one that's assigned, whether you do it in code or in IB. And if you're doing it in IB, make sure the data source object is given the correct class name. – Phillip Mills Oct 20 '12 at 01:15
  • what code do you want? I can provide it. – Nick Scottman Oct 20 '12 at 01:21
  • Make sure you have added this line in your code, for setting picker view datasource to self, pickername.dataSource = self; – jireh Oct 20 '12 at 03:13
  • i put that line in under the `data = [[NSMutableArray alloc] initWithObjects:@"Delta", @"Distance", nil];` line. Is that wrong because now all lines of the picker are "?" – Nick Scottman Oct 23 '12 at 01:53

0 Answers0