-1

Ok I am trying to create a simple TableView app that when the row is selected, transitions to a WebView. 我正在使用故事板,并且确实正确连接了我的链接。我收到如下错误。我一直在关注 Lynda.com 的教程和appcoda.com的教程,两者都使用了我在下面尝试过的方法,即使用“指南”或任何他们的 NSObject 类的标题。我真的很困惑和困惑,因为我无法弄清楚为什么它不会识别它。我试过删除@property (nonatomic, strong) Guide *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];
4

3 回答 3

0

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

作为类指南 isEqualToString: 你得到一个错误。

  • 假设它是一个强大的向导,您要么在某个地方错误地与向导一起工作
  • 或者你传递一些方法(可能来自 tableView 数据源)一个指南,它通常假设一个字符串
于 2013-05-05T18:05:48.777 回答
0

出现错误是因为您正在从数组中检索 Guide 实例,并认为您正在接收htmlFileNameorhtmlListName在您的-cellForRowAtIndexPath:方法中。

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

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

-viewDidLoad此外,您可以使用 for 循环或 NSFastEnumeration ,而不是手动设置实例化方法中的每个 Guide 实例:

- (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
    }
}
于 2013-05-09T18:09:32.257 回答
0
-[Guide isEqualToString:]

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

于 2013-05-05T16:58:52.310 回答