Re: [問題] 如何 NSCFString 轉換 NSString ??
NSCFString 繼承自 NSString,可以這樣玩玩看:
NSLog(@"NSCFString:%@", [[NSClassFromString(@"NSCFString") superclass] superclass]);
NSCFString 是 NSMutableString 的 subclass
NSMutableString 是 NSString 的 subclass
附上我部分代碼:
我是在實做
(UITableViewCell*)tableView:(UIableView*)tableView
cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
UIImage *img =[[[UIImage alloc]init]autorelease];
//self.imgUrlArray 是我放照片路徑的陣列
NSString *imgUrl = [self.imgUrlArray objectAtIndex:indexPath.row];
//要比對路徑來源是否為http,再做接下來動作
if([[imgUrl substringToIndex:4]isEqualToString:@"http"])
{......}
}
問題就在於取出來的imgUrl類型是NSCFString!!!!!
我依照zonble大大的做法改為:
NSString *test = [[NSClassFromString(@"NSCFString") superclass]superclass];
//會出現error 說明test is not a CFString Variable
另外依照phstudy大的作法
NSString *imgUrl = [NSString stringWithString:
(NSString*)[self.imgUrlArray objectAtIndex:indexPath.row]];
//依然是無法copy到NSString裡面,有設中斷點看他類型是NSCFString
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.127.137.224
※ 編輯: alan07 來自: 59.127.137.224 (05/27 11:39)
※ 編輯: alan07 來自: 59.127.137.224 (05/27 11:39)
推
05/27 11:45, , 1F
05/27 11:45, 1F
→
05/27 11:48, , 2F
05/27 11:48, 2F
→
05/27 11:48, , 3F
05/27 11:48, 3F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 3 之 7 篇):
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章