PDA

View Full Version : xcode 'NSInvalidArgumentException', reason: '-[cure superview]: unrecognized selector




borgy1
Apr 29, 2011, 09:52 PM
i am not sure why i am getting this error
i created a regular tab bar application
made 5 tabs (compiles and runs)
then put a tableview in one of the tabs , put the code below and i get this error


cure.h
---------------------------------------------
#import <UIKit/UIKit.h>

@interface cure : UIViewController
<UITableViewDataSource, UITableViewDelegate>
{
NSArray *exercises;
}

@end
---------------------------------------------
cure.m
---------------------------------------------
#import "cure.h"

@implementation cure

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

// create a cell
if ( cell == nil) {
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"cell"];
}

// set the main text
cell.textLabel.text = [exercises objectAtIndex:indexPath.row];

// return the cell.
return cell;
}


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
exercises = [[NSArray alloc]
initWithObjects:@"An Interesting Title",
@"A Not That Interesting Title",
@"And Still Another Title", nil];

[super viewDidLoad];
}



- (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.
}

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


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

@end

---------------------------------------------
in mainwindows.xib
i have the right tab class name "cure"
---------------------------------------------
error
---------------------------------------------
2011-04-29 22:22:06.446 week 3 week clear [4950:40b] -[cure superview]: unrecognized selector sent to instance 0x4e3b7b0
2011-04-29 22:22:06.451 peek 3 week clear [4950:40b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[cure superview]: unrecognized selector sent to instance 0x4e3b7b0'
*** Call stack at first throw:
(
<br>0 CoreFoundation 0x00dc15a9 __exceptionPreprocess + 185
<br>1 libobjc.A.dylib 0x00f15313 objc_exception_throw + 44
<br>2 CoreFoundation 0x00dc30bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
<br>3 CoreFoundation 0x00d32966 ___forwarding___ + 966
<br>4 CoreFoundation 0x00d32522 _CF_forwarding_prep_0 + 50
<br>5 UIKit 0x002e2365 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 77
<br>6 UIKit 0x002e0aa3 -[UIView(Hierarchy) addSubview:] + 57
<br>7 UIKit 0x002e87c1 -[UIView initWithCoder:] + 840
<br>8 Foundation 0x00017c24 _decodeObjectBinary + 3296
<br>9 Foundation 0x00016d91 _decodeObject + 224
<br>10 UIKit 0x004ac979 -[UIRuntimeConnection initWithCoder:] + 212
<br>11 Foundation 0x00017c24 _decodeObjectBinary + 3296
<br>12 Foundation 0x000189f5 -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 1354
<br>13 Foundation 0x00019024 -[NSArray(NSArray) initWithCoder:] + 596
<br>14 Foundation 0x00017c24 _decodeObjectBinary + 3296
<br>15 Foundation 0x00016d91 _decodeObject + 224
<br>16 UIKit 0x004abc36 -[UINib instantiateWithOwner:options:] + 804
<br>17 UIKit 0x004adab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
<br>18 UIKit 0x00363628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
<br>19 UIKit 0x00361134 -[UIViewController loadView] + 120
<br>20 UIKit 0x0036100e -[UIViewController view] + 56
<br>21 UIKit 0x00373f54 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 120
<br>22 UIKit 0x00372aaa -[UITabBarController transitionFromViewController:toViewController:] + 64
<br>23 UIKit 0x003748a2 -[UITabBarController _setSelectedViewController:] + 263
<br>24 UIKit 0x00374711 -[UITabBarController _tabBarItemClicked:] + 352
<br>25 UIKit 0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119
<br>26 UIKit 0x004b3ce6 -[UITabBar _sendAction:withEvent:] + 422
<br>27 UIKit 0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119
<br>28 UIKit 0x00341799 -[UIControl sendAction:to:forEvent:] + 67
<br>29 UIKit 0x00343c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
<br>30 UIKit 0x00341750 -[UIControl sendActionsForControlEvents:] + 49
<br>31 UIKit 0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119
<br>32 UIKit 0x00341799 -[UIControl sendAction:to:forEvent:] + 67
<br>33 UIKit 0x00343c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
<br>34 UIKit 0x003427d8 -[UIControl touchesEnded:withEvent:] + 458
<br>35 UIKit 0x002d5ded -[UIWindow _sendTouchesForEvent:] + 567
<br>36 UIKit 0x002b6c37 -[UIApplication sendEvent:] + 447
<br>37 UIKit 0x002bbf2e _UIApplicationHandleEvent + 7576
<br>38 GraphicsServices 0x01719992 PurpleEventCallback + 1550
<br>39 CoreFoundation 0x00da2944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
<br>40 CoreFoundation 0x00d02cf7 __CFRunLoopDoSource1 + 215
<br>41 CoreFoundation 0x00cfff83 __CFRunLoopRun + 979
<br>42 CoreFoundation 0x00cff840 CFRunLoopRunSpecific + 208
<br>43 CoreFoundation 0x00cff761 CFRunLoopRunInMode + 97
<br>44 GraphicsServices 0x017181c4 GSEventRunModal + 217
<br>45 GraphicsServices 0x01718289 GSEventRun + 115
<br>46 UIKit 0x002bfc93 UIApplicationMain + 1160
<br>47 peek 3 week clear 0x00002658 main + 102
<br>48 peek 3 week clear 0x000025e9 start + 53
)
terminate called after throwing an instance of 'NSException'
Program received signal: “SIGABRT”.

---------------------------------------------
what am i doing wrong?
thank you



Shawnpk
Apr 30, 2011, 10:40 PM
It looks like in cure.h you have UIViewController as the super class. If that class is supposed to be a tableview, change UIViewController to UITableViewController. Also, I don't see the method for how many sections are in your tableview. Make sure you are using the required methods for the delegate and datasource. Finally, I see you're returning 1 for how many rows are in your tableview, but your array has 3 items in it.

jnoxx
May 1, 2011, 06:55 AM
It looks like in cure.h you have UIViewController as the super class. If that class is supposed to be a tableview, change UIViewController to UITableViewController. Also, I don't see the method for how many sections are in your tableview. Make sure you are using the required methods for the delegate and datasource. Finally, I see you're returning 1 for how many rows are in your tableview, but your array has 3 items in it.

He gave the delegate methods of UITableView to his UIViewController, so that's not a problem.
But u need the sections code. or it won't show anyways.
Don't see the problem otherwise, or it's an IB Error >.>

Shawnpk
May 1, 2011, 10:19 AM
I wasn't near my computer yesterday when I replied to your thread, but now I am. I created a new Tabbar project in Xcode and copied and pasted your code directly into it. It worked just fine so maybe when you hooked things up in Interface Builder something went wrong (just like jnoxx said).

PhoneyDeveloper
May 1, 2011, 12:10 PM
Where is the outlet for the tableView? Is there a tableview in the nib? Most likely either there is a wrong connection in the nib or a toplevel object in the nib isn't being retained. Is it possible that you connected the cure object in the nib to another view controller's view property?