【问题标题】:Why 'TableViewController' may not respond to '-setNames:'为什么'TableViewController' 可能不响应'-setNames:'
【发布时间】:2011-01-03 19:31:24
【问题描述】:

我是 iPhone 开发和 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

实现文件。

#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];
}

调试控制台输出

2011-01-03 13:06:21.287 FishID[826:207] -[FishTableViewController setfishNames:]:无法识别的选择器发送到实例 0x5d0d340
2011-01-03 13:06:21.289 FishID[826:207] *** 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[FishTableViewController setfishNames:]:无法识别的选择器发送到实例 0x5d0d340”
*** 第一次抛出调用堆栈:
(
    0 核心基础 0x0238e919 __exceptionPreprocess + 185
    1 libobjc.A.dylib 0x024dc5de objc_exception_throw + 47
    2核心基础0x0239042b-[NSObject(NSObject)不识别选择器:]+187
    3 核心基础 0x02300116 ___forwarding___ + 966
    4 核心基础 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 基础 0x00031cea __NSFireDelayedPerform + 441
    10 核心基础 0x0236fd43 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
    11 核心基础 0x02371384 __CFRunLoopDoTimer + 1364
    12 核心基础 0x022cdd09 __CFRunLoopRun + 1817
    13 核心基础 0x022cd280 CFRunLoopRunSpecific + 208
    14 核心基础 0x022cd1a1 CFRunLoopRunInMode + 97
    15 图形服务 0x02bf32c8 GSEventRunModal + 217
    16 图形服务 0x02bf338d GSEventRun + 115
    17 UIKit 0x002c0b58 UIApplicationMain + 1160
    18 FishID 0x00002370 主要 + 102
    19 FishID 0x00002301 开始 + 53
    20 ??? 0x00000001 0x0 + 1
)
在抛出“NSException”实例后调用终止
节目接收信号:“SIGABRT”。

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    naming conventions of Cocoa and Cocoa Touch 表示正确的方法名称是 setFishNames:,而不是 setfishNames:(注意大小写差异)Objective-C 中的方法名称区分大小写。

    【讨论】:

    • @5lb 低音不用担心。一段时间后,约定和语法之类的东西变得非常根深蒂固,但是习惯 Cocoa 的做事方式肯定需要一些时间。 :)
    【解决方案2】:

    由于您将 fishNames 合成为属性,因此您还可以这样做:

    retController.fishNames = fishSubCategory;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-14
      • 2020-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-15
      • 1970-01-01
      相关资源
      最近更新 更多