objective-c - xcode 'NSInvalidArgumentException',原因: '-[cure superview]: unrecognized selector sent to instance 0x4e3b7b0'

标签 objective-c ios

我不确定为什么会收到此错误 我创建了一个常规的标签栏应用程序 制作了 5 个选项卡(编译和运行) 然后在其中一个选项卡中放置一个表格 View ,将代码放在下面,我得到这个错误

治愈.h

#import <UIKit/UIKit.h>

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

@end

治愈.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

在 mainwindows.xib 中 我有正确的选项卡类名称“治愈”

错误

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:transition: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”.

我做错了什么? 谢谢

最佳答案

您可能已经在 Interface Builder 的“Identity”选项卡中将“cure”类分配给了 UIView。 “cure”是一个 View Controller ,因此它没有实现任何 UIView 方法(例如 -superview),因此在尝试加载 nib 时会抛出异常。

顺便说一句,你的代码中有一大堆漏洞,请阅读一些关于 Objective-C 中的内存管理的内容(也许还有关于 Cocoa 命名约定的内容)。

关于objective-c - xcode 'NSInvalidArgumentException',原因: '-[cure superview]: unrecognized selector sent to instance 0x4e3b7b0' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5839116/

相关文章:

ios - 在进行查询时使用谓词过滤来源

ios - 自定义 UITableView - iOs

iphone - 当调用 NSSet 的 setByAddingX 方法时,哪个集合的对象获胜?

ios - 如何将(可选的)完成处理程序关闭传递给 Swift 中的 transitionFromViewController?

objective-c - NSRunningApplication - 终止

objective-c - __block 说明符如何工作?

ios - Wikitude-风景模式下相机方向的概率

android - 移动应用程序的 Google Geocode API KEY 限制

ios - 关于 MPMediaItemCollection 项目 lastObject

ios - reloadItemsAtIndexPaths 上的 Collection View 崩溃