Tab ki,
Sizinde vaktinizi alıyorum kusruma bakmayın,
Burası tableview in hücrelerinin oluşturulduğu block
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let entry = self.entryList[indexPath.row]
if let yazar_id = entry.valueForKeyPath("yazar_id") as? String,var metin = entry.valueForKeyPath("metin") as? String{
let cell = tableView.dequeueReusableCellWithIdentifier("baslikEntryListTVCell", forIndexPath: indexPath) as! baslikEntryListTVCell
cell.cellIndexPath.append(indexPath)
self._currentIndexPath = indexPath
cell.attrText = NSMutableAttributedString(string: metin.regexReplace("<br />", replace: "\n"))
cell.entryMetinTextV.attributedText = cell.attrText
cell.derle(entry)
cell.kuladiWidthConst.constant = view.frame.width - 190
yazar_id
return cellOptimize(cell,yazar_id: yazar_id,metin: metin)
}else{
return tableView.dequeueReusableCellWithIdentifier("baslikEntryListTVCell", forIndexPath: indexPath) as! baslikEntryListTVCell
}
}
func cellOptimize(cell:baslikEntryListTVCell,yazar_id:String,var metin:String)->baslikEntryListTVCell{
Alamofire.request(.GET, consts._apiUrl, parameters: ["a":consts._apiKey,"n":"ben","uye_id":yazar_id])
.responseJSON { response in
if let JSON = response.result.value {
if let uyebilgileri = JSON["uyebilgileri"] as? NSObject{
if let uye_resim_url = uyebilgileri.valueForKey("resmum"){
cell.userImage.hnk_setImageFromURL(NSURL(string: uye_resim_url as! String)!)
}
}
}
}
cell.matchsGorsel = metin.regexMatch("(?<=\\(img:)(.*?)(?=\\))");
for match in cell.matchsGorsel{
if let src = match.valueForKey("src"),let location = match.valueForKey("location"){
if src.hasPrefix("#"){
let gorsel_id = (src as! String).regexReplace("#", replace: "")
let URLJ = NSURL(string: "
http://www.site.com/api/?a=huseyinul528754&n=galeri&w=gorsel_id&gorsel_id=\(gorsel_id)")!
cacheJ.fetch(URL: URLJ).onSuccess { JSON in
if let src = JSON.dictionary?["url_m"]{
self.entryTextViewURLtoIMGss(cell, location: (location as! Int), src: (src as! String), textView: cell.entryMetinTextV,leng: gorsel_id.characters.count)
}
}
}
}
}
}
func entryTextViewURLtoIMGs(cell:baslikEntryListTVCell,location:Int,var src:String,textView:UITextView,leng:Int=0){
var lng = src.characters.count
if(leng>0){ lng=leng}
src = src.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
let URL = NSURL(string: src)!
let fetcher = NetworkFetcher<NSData>(URL: URL)
//let i = String(cell.cellIndexPath[0].row)
print(derlenen)
cache.fetch(fetcher: fetcher).onSuccess { data in
let attributedString = cell.attrText
let textAttachment = NSTextAttachment()
if let image = UIImage(data: data){
textAttachment.image = image
cell.entryMetinTextV.attributedText = attributedString
// if cell.entryMetinTextV.text
let oldWidth = textAttachment.image!.size.width;
print(oldWidth)
//I'm subtracting 10px to make the image display nicely, accounting
//for the padding inside the textView
var scaleFactor = oldWidth / (textView.frame.width - 10)
if(image.size.width<textView.frame.width-100){
scaleFactor = oldWidth / oldWidth
}
scaleFactor = oldWidth / (textView.frame.width - 10)
//print("slace : \(scaleFactor) image size : \(image.size.width) org : \(image.size.width)")
textAttachment.image = UIImage(CGImage: textAttachment.image!.CGImage!, scale: scaleFactor, orientation: .Up)
let attrStringWithImage = NSAttributedString(attachment: textAttachment)
attributedString.replaceCharactersInRange(NSMakeRange(location,1), withAttributedString: attrStringWithImage)
let mysRange = NSRange(location:0, length:5) // range of "Swift"
let mysCustomAttribute = ["click":"src:\(src),type:image"]
attributedString.addAttributes(mysCustomAttribute, range: mysRange)
print(attributedString.length)
attributedString.addAttribute(NSFontAttributeName,value: UIFont(name: "AmericanTypewriter-Bold",size:9)!,range: NSRange(location:0,length:5))
cell.entryMetinTextV.attributedText = attributedString
if let _ = self._currentIndexPath {
self.baslikEntryListTV.beginUpdates()
//self.baslikEntryListTV.reloadRowsAtIndexPaths(cell.cellIndexPath, withRowAnimation: UITableViewRowAnimation.None)
self.derlenen[cell.cellIndexPath[0].row] = 1
self.baslikEntryListTV.endUpdates()
print(self.derlenen)
print(" burada \(cell.cellIndexPath[0].row)")
}
else {
// `_currentIndexPath` is nil.
// Error handling if needed.
}
}
}
}
Dosyalar birbirine entegre ve buyuk olduğu için yollayamadım, app i gondermem gerkiyorsa, sorunun olduğu alanın ufak bir örneğini hazırlayıp yollayabilrim.
Şuanda scrool yaptığımda diğer hucreler yüklenip ardından resim yükleme tamamladığında yenilendiğinden, bu art arda oluyor ve sayfada celler üst üste gelip, NSRangeException hatasını aliyorum.