无法识别的选择器发送到Tableviewcontroller中的实例

时间:2013-05-05 16:42:43

标签: ios objective-c uitableview unrecognized-selector

好的我正在尝试创建一个简单的TableView应用程序,当选择该行时,转换为WebView。我正在使用故事板,并确保我的链接正确连接。我收到的错误如下所示。我一直关注Lynda.com上的教程以及来自appcoda.com的教程,并且都使用我在下面尝试的方法,使用“指南”或者他们的类与NSObject的标题是什么。我真的很困惑和困惑,因为我无法弄清楚为什么它不会认出它。我试过删除@property(非原子,强)指南* html;部分但仍然得到相同的消息。我希望这对你来说足够具体。哦,我使用的是最新版本的xcode。

我的错误讯息是

-[Guide isEqualToString:]: unrecognized selector sent to instance 0x8543aa0
2013-05-05 11:33:29.076 hikingHelp[5522:c07] *** Terminating app due to uncaught exception    NSInvalidArgumentException', reason: '-[Guide isEqualToString:]: unrecognized selector 
sent to instance 0x8543aa0'
*** First throw call stack:

我的Guide.h文件如下:

#import <Foundation/Foundation.h>
#import "TableViewController.h"
#import "DetailViewController.h"
#import "MapViewController.h"


@interface Guide : NSObject

@property (nonatomic, strong) NSString *htmlListName;
@property (nonatomic, strong) NSString *htmlFileName;

@end

我的TableViewController.h:

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

@interface TableViewController : UITableViewController
{
NSMutableArray *htmlFiles;
}
@property (nonatomic, strong) Guide *html;
@end

我的TableViewController.m在 - (void)viewDidLoad:

- (void)viewDidLoad
{
[super viewDidLoad];

htmlFiles = [[NSMutableArray alloc] init];

Guide *html = [[Guide alloc] init];
[html setHtmlListName:@"Survival Planning"];
[html setHtmlFileName:@"survivalplanning.html"];
[htmlFiles addObject:html];

html = [[Guide alloc] init];
[html setHtmlListName:@"Survival Kits"];
[html setHtmlFileName:@"survivalkits.html"];
[htmlFiles addObject:html];

html = [[Guide alloc] init];
[html setHtmlListName:@"Basic Survivl Medicine"];
[html setHtmlFileName:@"basichealth.html"];
[htmlFiles addObject:html];

html = [[Guide alloc] init];
[html setHtmlListName:@"Shelters"];
[html setHtmlFileName:@"shelters.html"];
[htmlFiles addObject:html];

html = [[Guide alloc] init];
[html setHtmlListName:@"Water Procurement"];
[html setHtmlFileName:@"waterprocurement.html"];
[htmlFiles addObject:html];

html = [[Guide alloc] init];
[html setHtmlListName:@"Firecraft"];
[html setHtmlFileName:@"firecraft.html"];
[htmlFiles addObject:html];

html = [[Guide alloc] init];
[html setHtmlListName:@"Food"];
[html setHtmlFileName:@"food.html"];
[htmlFiles addObject:html];

html = [[Guide alloc] init];
[html setHtmlListName:@"Edible Plants"];
[html setHtmlFileName:@"edibleplant.html"];
[htmlFiles addObject:html];

html = [[Guide alloc] init];
[html setHtmlListName:@"Posionous Plants"];
[html setHtmlFileName:@"posionousplants.html"];
[htmlFiles addObject:html];

html = [[Guide alloc] init];
[html setHtmlListName:@"Dangerous Animals"];
[html setHtmlFileName:@"dangerousanimals.html"];
[htmlFiles addObject:html];

html = [[Guide alloc] init];
[html setHtmlListName:@"Water Crossing"];
[html setHtmlFileName:@"watercrossings.html"];
[htmlFiles addObject:html];

html = [[Guide alloc] init];
[html setHtmlListName:@"Find Directions"];
[html setHtmlFileName:@"directions.html"];
[htmlFiles addObject:html];

html = [[Guide alloc] init];
[html setHtmlListName:@"Signaling Techniques"];
[html setHtmlFileName:@"signaling.html"];
[htmlFiles addObject:html];

3 个答案:

答案 0 :(得分:0)

-[Guide isEqualToString:]

指南是一个不是字符串的类,所以它如何将类与字符串进行比较。

答案 1 :(得分:0)

您正在调用在某个类型isEqualToString:的自定义对象上的NSString实例上定义的方法Guide

由于类指南isEqualToString:您收到错误。

  • 如果你错误地使用指南假设它是一个强大的
  • 或者您传递一些方法(可能来自tableView dataSource)指南和IT通常假设一个字符串

答案 2 :(得分:0)

由于您正在从阵列中检索Guide实例,并且认为您在htmlFileName方法中收到了htmlListName-cellForRowAtIndexPath:,因此出现错误。

不使用cell.textLabel.text = [htmlFiles objectAtIndex:indexPath.row];,而是使用以下内容:

Guide *rowGuide = htmlFiles[indexPath.row];
cell.textLabel.text = rowGuide.htmlFileName;

此外,您可以使用for循环或NSFastEnumeration来代替手动设置实例化-viewDidLoad方法中的每个指南实例:

- (void)viewDidLoad {
    [super viewDidLoad];

    htmlFiles = [[NSMutableArray alloc] init];

    NSArray *htmlListNames = @[@"Survival Planning", @"Survival Kits", @"Basic Survivl Medicine", @"Shelters", @"Water Procurement", @"Firecraft", @"Food", @"Edible Plants", @"Poisonous Plants", @"Dangerous Animals", @"Water Crossing", @"Find Directions", @"Signalling Technique"];
    NSArray *htmlFileNames = @[@"survivalplanning.html", @"survivalkits.html", @"basichealth.html", @"shelters.html", @"waterprocurement.html", @"firecraft.html", @"food.html", @"edibleplant.html", @"posionousplants.html", @"dangerousanimals.html", @"watercrossings.html", @"directions.html", @"signaling.html"];

    for (NSUInteger idx = 0; idx < [htmlListNames count]; idx++) {
        Guide *guide = [[Guide alloc] init];
        [guide setHtmlListName:htmlListNames[idx]];
        [guide setHtmlFileName:htmlFileNames[idx]];
        [htmlFiles addObject:guide];
        [guide release]; // if you're not using arc
    }
}