Re: [問題] 如何 NSCFString 轉換 NSString ??

看板MacDev作者 (幸福得沒有理由)時間14年前 (2011/05/27 13:51), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串6/7 (看更多)
※ 引述《alan07 (幸福得沒有理由)》之銘言: : : NSURL *url = [NSURL URLWithString: : : [self.imgUrlArray objectAtIndex:indexPath.row] ]; : : if( [[url scheme] compare:@"http"] == NSOrderSame ) : : ... : : 試試看這樣 : 我剛試了問題還是出在同個地方, : NSURL *url = [NSURL URLWithString:(NSString*)] //他對象的是NSString : //而不是NSCFString : 謝謝您的回覆,繼續等待有緣人解答 剛又試一下 我本來代碼 (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"]) {......} img = [UIImage imageNamed:imgUrl]; cell.imgView.image = img; cell.subjectLbl.text = [self.subjectArray objectAtIndex:indexPath.row]; } //********************************************************** 我想既然這個可行取出來可能是 @"dfghdfh" 的Cstring cell.subjectLbl.text = [self.subjectArray objectAtIndex:indexPath.row]; 所以剛就以嘗試 結果還是失敗=> 取出來是亂碼 NSString *imgUrl =[ [NSSTring alloc]initwithCstring:(const char*) [self.imgUrlArray objectAtIndex:indexPath.row]]; 後來加上encoding:NSUTF8StringEncoding NSString *imgUrl =[ [NSSTring alloc]initwithCstring:(const char*) [self.imgUrlArray objectAtIndex:indexPath.row] encoding:NSUTF8StringEncoding]; 取出來變成nil, 有沒有人NSCFString知道給點提示?謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.127.137.224 ※ 編輯: alan07 來自: 59.127.137.224 (05/27 13:56)
文章代碼(AID): #1DtplK9C (MacDev)
文章代碼(AID): #1DtplK9C (MacDev)