我的iPhone应用程序崩溃并显示错误:

- [__NSCFDictionary stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x99f60b0

这是我的代码
     NSString * strData;
    AppDelegate * delegate =(AppDelegate *)[[UIApplication sharedApplication]委托];
    如果(delegate.respondInsightIndex)
    {
        strData = [insights objectAtIndex:index];
    }
    其他
    {
        strData = [insights lastObject];
    }

NSString *strReplace = [NSString stringWithFormat:@"%@",[strData stringByReplacingOccurrencesOfString:@"%20" withString:@" "]];


这是我的方法,崩溃再次发生

- (void) setComments:(NSArray*)comments {
NSString * htmlString;
if ( [UIHelper isPad] )
    htmlString = @"<html><style type=\"text/css\">body{padding:15px 40px 0 40px; font-family: Helvetica;"
                "font-size: 14px;"
                "color: #888888;"
                "line-height: 50%"
                "},</style><body>";
else
    htmlString = @"<html><style type=\"text/css\">body{padding:8px 20px 0 20px; font-family: Helvetica;"
                "font-size: 11px;"
                "color: #888888;"
                "},</style><body>";

for ( NSString * single in comments ) {
    if ( single == nil )
        single = @"";

    if ([single isKindOfClass:[NSString class]]) {
        single = [single stringByReplacingOccurrencesOfString:@"%20" withString:@" "];
    }
    NSString * str ;
    if([UIHelper isPad ])
    {
        str = [NSString stringWithFormat:@"%@<br/><hr color=#555555><p align=\"right\" style=\"font-size:12px;\">Username</p>", single];
    }
    else {
        str = [NSString stringWithFormat:@"%@<br/><hr color=#555555><p align=\"right\" style=\"font-size:9px;\">Username</p>", single];
    }

    htmlString = [NSString stringWithFormat:@"%@%@", htmlString, str];
}
htmlString = [NSString stringWithFormat:@"%@%@", htmlString, @"</body></html>"];
if ( [contentView respondsToSelector:@selector(loadHTMLString:baseURL:)] )
    [contentView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.secondprizm.com"]];


}

最佳答案

因此,这意味着您正在尝试在- stringByReplacingOccurrencesOfString实例上使用方法NSDictionary,这当然是行不通的。

对象strData不是您认为的NSString对象。它实际上是NSDictionary的对象。

08-25 07:57