2012-06-26 34 views
0

我正在使用一些正則表達式來獲取xml中的第一個URL,它是指向照片的鏈接,並將該照片設置爲單元格的imageview圖像。這裏是我的代碼:TableView單元格的設置圖像NSURL isResizable錯誤

NSString *thearticleImage = entry.articleImage; 
    NSRegularExpression *expression = [NSRegularExpression regularExpressionWithPattern:@"(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»「」‘’]))" options:NSRegularExpressionCaseInsensitive error:NULL]; 
    NSString *someString = thearticleImage; 
    self.theurl = [someString substringWithRange:[expression rangeOfFirstMatchInString:someString options:NSMatchingCompleted range:NSMakeRange(0, [someString length])]]; 


    cell.imageView.image = [NSURL URLWithString:theurl]; 

我結束了剛開的錯誤:

'-[NSURL _isResizable]: unrecognized selector sent to instance 0x882e250' 

問題是什麼這個?

回答

0

不能使用URL來imageView.image所以你可以使用這個像下面

NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"your image link"]]; 
UIImage *downloadedImage = [UIImage imageWithData:imageData]; 
cell.imageView.image = downloadedImage; 

但它會產生碰撞...

注意

要使用此崩潰克服你必須異步點擊URL。這樣它不會產生崩潰,表格將自由滾動

相關問題