2012-10-29 131 views
0

我在第二個tableview時總是出錯。我使用storyboard創建一個簡單的應用程序。我的應用第一次運行時,它會顯示我創建的數據列表。如果用戶點擊該行,我想更改爲其他頁面,在其他頁面上也有一個tableview。我也對數據列表進行了硬編碼,但是我沒有顯示出來。從UITableView中選擇單元格並轉到另一個UITableView

我總是得到一個錯誤在這一部分

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SubSiteCellDetail"]; 
    cell.textLabel.text = [ListDetailSubSite objectAtIndex:indexPath.row]; //this always give me the error 
    return cell; 
} 

這裏是我創建的數據列表

ListDetailSubSite = [NSMutableArray arrayWithCapacity:10]; 
SubSite *detailSubSite = [[SubSite alloc] init]; 
detailSubSite.sSubSiteName = [subsite.sSubSiteName stringByAppendingString:@"1"]; 
[ListDetailSubSite addObject:detailSubSite]; 


detailSubSite = [[SubSite alloc] init]; 
detailSubSite.sSubSiteName = [subsite.sSubSiteName stringByAppendingString:@"2"]; 
[ListDetailSubSite addObject:detailSubSite]; 

這裏是如何,我從UITableView中移動到另一個UITableView的。

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    if ([[segue identifier] isEqualToString:@"ShowSubSiteDetail"]) { 
     NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 
     SubSite *subsetSelected = [ListSubSite objectAtIndex:indexPath.row]; 
     [[segue destinationViewController] setSubsite:subsetSelected]; 
    } 
} 

這是我的錯誤看起來像

2012-10-29 15:18:11.127 UniversalStoryBoard[5256:f803] -[SubSite isEqualToString:]: unrecognized selector sent to instance 0x9355340 
2012-10-29 15:18:11.129 UniversalStoryBoard[5256:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SubSite isEqualToString:]: unrecognized selector sent to instance 0x9355340' 
*** First throw call stack: 
(0x13ce022 0x155fcd6 0x13cfcbd 0x1334ed0 0x1334cb2 0x1580ff 0x4fb1 0xb2c54 0xb33ce 0x9ecbd 0xad6f1 0x56d21 0x13cfe42 0x1d86679 0x1d90579 0x1d154f7 0x1d173f6 0x1d16ad0 0x13a299e 0x1339640 0x13054c6 0x1304d84 0x1304c9b 0x12b77d8 0x12b788a 0x18626 0x1fcd 0x1f35) 
terminate called throwing an exception 

這裏是圖:

Picture

類SubSite.h

#import <UIKit/UIKit.h> 

@interface SubSite : NSObject 
@property (nonatomic, copy) NSString *sSubSiteName; 

@end 

類SubSite.m

#import "SubSite.h" 

@implementation SubSite 
@synthesize sSubSiteName; 

@end 

任何人都可以幫我解決這個問題嗎?謝謝。

回答

1

這個問題可能是因爲在cell.textLabel.text = [ListDetailSubSite objectAtIndex:indexPath.row];細胞需要一個字符串,而不是一個ListDetailSubSite對象..

類似的錯誤在這個環節解決:

Why am I getting an isEqualToString error in this Cocoa code?

既然你提到你已經創建了一個Subsite類,你可以嘗試這種方法..基本上你需要確保輸入到cell.textLabel.text是一個NSString對象..

+0

嗨,謝謝你的答案..它真的很有幫助。再次感謝。 :) –

+0

很高興它解決了.. :) – Coder

1

您需要粘貼DidSelectRowAtIndexPath方法的代碼。請提供給我們。

+0

你忘了補充: '電池= [UITableViewCell的頁頭] initwithstyle:UITableviewCellStyleDefault:resuseidentifier:符]]' 請在的cellForRowAtIndexPath功能 感謝 –

+0

嗨,我想我已經使用的UITableViewCell添加以下代碼* cell = [tableView dequeueReusableCellWithIdentifier:@「SubSiteCellDetail」] ;.但我也嘗試使用你的指令,仍然失敗,並給我同樣的錯誤.. –

+0

請貼上你得到的錯誤,這將有助於更深入地診斷問題。 –

1

你發現了什麼錯誤? 和你試試這個

cell.textLabel.text = [NSString stringWithFormat @"%@",[ListDetailSubSite objectAtIndex:indexPath.row]]; 

我認爲這個問題的發生是因爲cell.textlable.text接受NSString,所以你需要轉換你的對象

你可以做到這一點,而不是

Subset *tmp = [ListDetailSubSite objectAtIndex:indexPath.row]; 
cell.textLabel.text = [NSString stringWithFormat:@"%@",tmp.sSubSetName]; 
+0

嗨,謝謝你的回答。幾乎解決了它,但爲什麼輸出就像內存地址?我怎樣才能從indexpath.row獲取文本?謝謝。 –

+0

你下了SubSite嗎? – usergio2

+0

雅,SubSite是一個類。我將在SubSite類中添加。 –

0
cell.textLabel.text = [ListDetailSubSite objectAtIndex:indexPath.row] 

應換成

cell.textLabel.text = [[ListDetailSubSite objectAtIndex:indexPath.row] sSubSiteName] 
+2

嗨,謝謝你的回答。但說實話,有什麼不同?我的意思是你的答案。 –

+0

對不起,我犯了一個錯誤,現在我糾正它..hope不會錯過你 – tassar

+0

嗨,它好吧..不用擔心。我投你的答案,因爲你的答案也是正確的..謝謝。 :) –

相關問題