为什么'TableViewController'可能无法响应'-setNames:'

5lb*_*ass 0 iphone objective-c

我是iPhone dev和Object-C的菜鸟.不知道为什么我的'TableViewController'可能无法响应'-setNames:'任何帮助将不胜感激.

头文件

#import <UIKit/UIKit.h>
#import "FishViewController.h"

@interface FishTableViewController : UITableViewController {
    NSArray* fishNames;
}

+ (FishTableViewController*) fishTableViewControllerWithFishNames:(NSArray*)fishSubCategory;

@property (nonatomic, retain) NSArray* fishNames;
@end
Run Code Online (Sandbox Code Playgroud)

实施文件.

#import "FishTableViewController.h"

#define FishTableViewControllerNibName @"FishTableViewController"

@implementation FishTableViewController

@synthesize fishNames;

+ (FishTableViewController*) fishTableViewControllerWithFishNames:(NSArray*)fishSubCategory {
    // Warning occurs on the following line
    FishTableViewController* retController = [[FishTableViewController alloc] initWithNibName:FishTableViewControllerNibName bundle:nil];

    [retController setfishNames:fishSubCategory];

    return [retController autorelease];
}
Run Code Online (Sandbox Code Playgroud)

调试控制台输出

2011-01-03 13:06:21.287 FishID[826:207] -[FishTableViewController setfishNames:]: unrecognized selector sent to instance 0x5d0d340
2011-01-03 13:06:21.289 FishID[826:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FishTableViewController setfishNames:]: unrecognized selector sent to instance 0x5d0d340'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x0238e919 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x024dc5de objc_exception_throw + 47
    2   CoreFoundation                      0x0239042b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x02300116 ___forwarding___ + 966
    4   CoreFoundation                      0x022ffcd2 _CF_forwarding_prep_0 + 50
    5   FishID                              0x00002a75 +[FishTableViewController fishTableViewControllerWithFishNames:] + 116
    6   FishID                              0x000028d7 -[RootViewController tableView:didSelectRowAtIndexPath:] + 252
    7   UIKit                               0x00324718 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
    8   UIKit                               0x0031affe -[UITableView _userSelectRowAtIndexPath:] + 219
    9   Foundation                          0x00031cea __NSFireDelayedPerform + 441
    10  CoreFoundation                      0x0236fd43 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
    11  CoreFoundation                      0x02371384 __CFRunLoopDoTimer + 1364
    12  CoreFoundation                      0x022cdd09 __CFRunLoopRun + 1817
    13  CoreFoundation                      0x022cd280 CFRunLoopRunSpecific + 208
    14  CoreFoundation                      0x022cd1a1 CFRunLoopRunInMode + 97
    15  GraphicsServices                    0x02bf32c8 GSEventRunModal + 217
    16  GraphicsServices                    0x02bf338d GSEventRun + 115
    17  UIKit                               0x002c0b58 UIApplicationMain + 1160
    18  FishID                              0x00002370 main + 102
    19  FishID                              0x00002301 start + 53
    20  ???                                 0x00000001 0x0 + 1
)
terminate called after throwing an instance of 'NSException'
Program received signal:  “SIGABRT”.

Dav*_*ong 5

Cocoa和Cocoa Touch命名约定意味着正确的方法名称setFishNames:不是setfishNames:(注意大写差异)方法名称在Objective-C中区分大小写.