2012-10-29 132 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

嗨,它好吧..不用担心。我投你的答案,因为你的答案也是正确的..谢谢。 :) –

相关问题