开发者

xcode 'NSInvalidArgumentException', reason: '-[cure superview]: unrecognized selector sent to instance 0x4e3b7b0'

开发者 https://www.devze.com 2023-03-02 08:02 出处:网络
i am not sure why i am getting this error i created a regular tab bar application made 5 tabs (compiles and runs)

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:
(
    0   CoreFoundation                      0x00dc15a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x00f15313 objc_exception_throw + 44
    2   CoreFoundation                      0x00dc30bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x00d32966 ___forwarding___ + 966
    4   CoreFoundation                      0x00d32522 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x002e2365 -[UIView(Internal) _addSubview:positioned:relativeTo:] + 77
    6   UIKit                               0x002e0aa3 -[UIView(Hierarchy) addSubview:] + 57
    7   UIKit                               0x002e87c1 -[UIView initWithCoder:] + 840
    8   Foundation                          0x00017c24 _decodeObjectBinary + 3296
    9   Foundation                          0x00016d91 _decodeObject + 224
    10  UIKit                               0x004ac979 -[UIRuntimeConnection initWithCoder:] + 212
    11  Foundation                          0x00017c24 _decodeObjectBinary + 3296
    12  Foundation                          0x000189f5 -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 1354
    13  Foundation                          0x00019024 -[NSArray(NSArray) initWithCoder:] + 596
    14  Foundation                          0x00017c24 _decodeObjectBinary + 3296
    15  Foundation                          0x00016d91 _decodeObject + 224
    16  UIKit                               0x004abc36 -[UINib instantiateWithOwner:options:] + 804
    17  UIKit                               0x004adab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
    18  UIKit                               0x00363628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
    19  UIKit                               0x00361134 -[UIViewController loadView] + 120
    20  UIKit                               0x0036100e -[UIViewController view] + 56
    21  UIKit                               0x00373f54 -[UITabBarController transitionFromViewController:toViewController:t开发者_开发问答ransition:shouldSetSelected:] + 120
    22  UIKit                               0x00372aaa -[UITabBarController transitionFromViewController:toViewController:] + 64
    23  UIKit                               0x003748a2 -[UITabBarController _setSelectedViewController:] + 263
    24  UIKit                               0x00374711 -[UITabBarController _tabBarItemClicked:] + 352
    25  UIKit                               0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119
    26  UIKit                               0x004b3ce6 -[UITabBar _sendAction:withEvent:] + 422
    27  UIKit                               0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119
    28  UIKit                               0x00341799 -[UIControl sendAction:to:forEvent:] + 67
    29  UIKit                               0x00343c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    30  UIKit                               0x00341750 -[UIControl sendActionsForControlEvents:] + 49
    31  UIKit                               0x002b14fd -[UIApplication sendAction:to:from:forEvent:] + 119
    32  UIKit                               0x00341799 -[UIControl sendAction:to:forEvent:] + 67
    33  UIKit                               0x00343c2b -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
    34  UIKit                               0x003427d8 -[UIControl touchesEnded:withEvent:] + 458
    35  UIKit                               0x002d5ded -[UIWindow _sendTouchesForEvent:] + 567
    36  UIKit                               0x002b6c37 -[UIApplication sendEvent:] + 447
    37  UIKit                               0x002bbf2e _UIApplicationHandleEvent + 7576
    38  GraphicsServices                    0x01719992 PurpleEventCallback + 1550
    39  CoreFoundation                      0x00da2944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    40  CoreFoundation                      0x00d02cf7 __CFRunLoopDoSource1 + 215
    41  CoreFoundation                      0x00cfff83 __CFRunLoopRun + 979
    42  CoreFoundation                      0x00cff840 CFRunLoopRunSpecific + 208
    43  CoreFoundation                      0x00cff761 CFRunLoopRunInMode + 97
    44  GraphicsServices                    0x017181c4 GSEventRunModal + 217
    45  GraphicsServices                    0x01718289 GSEventRun + 115
    46  UIKit                               0x002bfc93 UIApplicationMain + 1160
    47  peek 3 week clear                    0x00002658 main + 102
    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


You have probably assigned the "cure" class to a UIView in the "Identity" tab in Interface Builder. "cure" is a view controller, so it doesn't implement any UIView methods (such as -superview), and thus throws an exception when trying to load the nib.

Btw, you have a whole bunch of leaks in your code, please read something about memory management in Objective-C (perhaps also about Cocoa naming conventions).

0

精彩评论

暂无评论...
验证码 换一张
取 消