2009-11-08 21 views
0

我有些奇怪的東西: 此代碼無效: cell.imvstatus.image = [UIImage imageNamed:[[tutorials objectAtIndex:indexPath.row] objectForKey:@「image」]] ;將對象轉換爲字符串iPhone SDK

此代碼的工作:

cell.imvstatus.image = [UIImage的imageNamed:@ 「ROR.png」];

而在對象有值「ROR.png」

請告訴我在上述一個問題?

如何找到解決方案? 我是否必須將其轉換爲字符串?

+0

回去接受一些解答您的老問題。 – 2012-02-03 19:34:57

回答

0

好的我已經找到它了:

image =「ROR.png \ n」;包含\ n

我不得不更換它。但是:

OK現在輸出的是: 2009-11-09 09:17:31.606 remotegui [1667:207]圖片:ROR.png 但當我寫出來的字符串長度的字符串是8個字符長:

2009-11-09 09:17:31.606 remotegui [1667:207] bildlength:8

+0

您可以使用此代碼刪除'\ n' 'NSString * string = @「firstname \ nlastname」; NSLog(@「%@」,string); string = [string stringByReplacingOccurrencesOfString:@「\ n」withString:@「」]; NSLog(@「%@」,string);' – 2011-11-04 06:29:02

0

嘗試鑄造它作爲像這樣的字符串:

NScell.imvstatus.image = [UIImage imageNamed: (NSString *) [[tutorials objectAtIndex:indexPath.row] objectForKey:@"image"] ];

的關鍵是(NSString *)

0

我們唯一可以假設的是[[tutorials objectAtIndex:indexPath.row] objectForKey:@"image"]不包含ROR.png。

嘗試通過(菜單運行>控制檯下,並查看控制檯輸出,在Xcode)將下面的代碼行做的NSLog調試:

NSLog(@"tutorials: %@", tutorials); 
NSLog(@"row index: %d", indexPath.row); 
NSLog(@"row content: %@", [tutorials objectAtIndex:indexPath.row]); 
NSLog(@"image: %@", 
    [[tutorials objectAtIndex:indexPath.row] objectForKey:@"image"]); 

有可能是意想不到的事情出現。