2013-05-05 42 views
-1

好吧我試圖創建一個簡單的TableView應用程序,當該行被選中時,轉換爲WebView。我正在使用故事板,並確保我的鏈接正確連接。我收到如下所示的錯誤。我一直在關注Lynda.com上的教程以及appcoda.com中的一個,它們都使用我在下面通過使用「指南」或任何NSObject類的標題嘗試的方法。我真的很困惑和困惑,因爲我無法弄清楚爲什麼它不會識別它。我試圖刪除@property(非原子,強大)Guide * html;但仍然得到相同的信息。我希望這對你來說足夠具體。哦,我正在使用最新版本的xcode。無法識別的選擇器發送到Tableviewcontroller中的實例

我的錯誤信息是

-[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]; 
+0

你的UITableView代碼在哪裏,你在哪裏檢查'isEqualToString'。 – icodebuster 2013-05-05 16:48:06

+2

哪行代碼導致異常?您發佈的任何代碼都不會導致錯誤。 – rmaddy 2013-05-05 16:48:21

+2

*你甚至爲循環兄弟?*獲取兩個NSArrays,一個用於htmlListName(NSStrings),另一個用於htmlFileName。循環訪問其中一個數組,並創建一個Guide實例,並將其每次添加到該數組中。 – 2013-05-05 16:53:28

回答

0

錯誤因爲您正在從數組中檢索Guide實例,因爲您在-cellForRowAtIndexPath:方法中正在接收htmlFileNamehtmlListName

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

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

而且,而非手動設置你的-viewDidLoad方法實例每個指南情況下,你可以使用一個for循環或交替NSFastEnumeration:

- (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 
    } 
} 
+0

非常感謝!此外,我要谷歌如何在for循環中設置數組,所以謝謝你的照顧! – kenthub 2013-05-10 18:42:46

+0

@ kenthub沒有問題,很高興它的工作! – 2013-05-11 01:13:03

0
-[Guide isEqualToString:] 

指南是一個類,它不是一個字符串,所以它如何將一個類與一個字符串進行比較。

+0

一個字符串也是一個類...你得到的問題正確,但你的答案沒有公式化正確 – 2013-05-05 18:01:11

+1

指南是NSObject的子類你可以[guideObj.htmlFileName isEqualToString:@「Matchedstring」]; – 2013-05-05 18:09:55

0

要調用其上的NSString實例定義Guide類型的自定義對象的地方

由於類指南isEqualToString的方法isEqualToString::你得到一個錯誤。

  • 無論是你的地方錯誤地指導工作,假設它是一個強大的
  • 或傳遞某種方法(也許從的tableView數據源)的指南,它通常假定一個字符串
相關問題