得到像malloc_error_break一样的错误

时间:2015-06-08 11:14:35

标签: ios swift

重新加载tableView应用程序崩溃,我收到错误 malloc:

  对象0x7f8c7b99be80的

错误:未分配被释放的指针   在malloc_error_break中设置断点以进行调试

我为它设置了符号断点 malloc_error_break

还尝试使用“Instruments”查找内存泄漏,但它只是在控制台中显示相同的错误,但这里没有任何内存泄漏。 如何解决这个问题。

(我使用的是8.3 SDK和6.3.1 Xcode)

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    var ResultCellIdentifier = "placementID"
    var LoadCellIdentifier = "LoadingCell"

    var count = self.arrayOfAllData.count as NSInteger
    if count == 0 && indexPath.row == 0 {
        let cell = tableView.dequeueReusableCellWithIdentifier("LoadingCell") as!  UITableViewCell
        return cell
    }
    else {
        let cell = tableView.dequeueReusableCellWithIdentifier("placementID") as!  PlacementsTableViewCell

        indexPATH = indexPath
        var tweet = self.arrayOfAllData.objectAtIndex(indexPath.row) as! NSDictionary

        let created_at = tweet.valueForKey("created_at") as? NSString
        var dateArray : NSArray = created_at!.componentsSeparatedByString(" ")
        if dateArray.count != 0 {
            let month = dateArray.objectAtIndex(1) as!  String
            let date = dateArray.objectAtIndex(2) as!  String

            cell.timeLabel.text = String(format: "%@ %@", date,month)
        }


        ///////////any url present in tweet text
        var entities = NSDictionary()
        entities = tweet.valueForKey("entities") as! NSDictionary

        var urlsArray = entities.valueForKey("urls") as! NSArray
        if urlsArray.count == 0 {

        }else {

            for item in urlsArray as! [NSDictionary] {
                let expanded_url = item.valueForKey("expanded_url") as? String
            }
        }
        ///////////

        var tweet_id_str = NSString()
        var user_id_str = NSString()
        var data = NSData()
        //            var name = NSString()
        ///////////count of retweets
        var retweet_count = tweet.valueForKey("retweet_count") as!  NSInteger

        var retweeted_status = tweet.valueForKey("retweeted_status") as! NSDictionary
        var favorite_count = retweeted_status.valueForKey("favorite_count") as!  NSInteger
        ///////////tweet id
        tweet_id_str = retweeted_status.valueForKey("id_str") as!  NSString

        if retweeted_status.isEqual(nil) {

        }
        else {
            var user = retweeted_status.valueForKey("user") as! NSDictionary
            ///////////last update
            let created_at = retweeted_status.valueForKey("created_at") as! NSString
            ///////////

            ///////////user name who added this tweet
            cell.titleLabel.text = user.valueForKey("name") as? String
            ///////////user id who added this tweet
            user_id_str = user.valueForKey("id_str") as!  NSString
            ///////////screen name
            let screen_name = user.valueForKey("screen_name") as!  NSString

            var followers_count = user.valueForKey("followers_count") as!  NSInteger

            ///////////profile image of the tweet

            cell.avatarImageView.image = UIImage(named: "Twitter Avatar.jpg")

            let profile_image_url = user.valueForKey("profile_image_url") as! NSString
            var imageUrl = NSURL(string: profile_image_url as String)

            let request: NSURLRequest = NSURLRequest(URL: imageUrl!)

            NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue(), completionHandler: {(response: NSURLResponse!,data: NSData!,error: NSError!) -> Void in
                if error == nil {

                    if data != nil {
                        var image = UIImage(data: data)
                        cell.avatarImageView.image = image
                    }
                }
            })


            if retweet_count >= 5 ||  favorite_count >= 15 || followers_count >= 30000 {
                cell.featuredImageView.hidden = false
                cell.featuredImageView.image = UIImage(named: "new feature star")
            }
            else {
                cell.featuredImageView.hidden = true
            }

        }

        cell.mailLabel.text = ""

        let tweetText = tweet.valueForKey("text") as? NSString
        cell.beattypeLabel.text = tweetText as? String

        if tweetText?.containsString("@gmail") == true{
            NSLog("Mail id is present at index : %d", indexPath.row)
            var words = NSArray()
            words = NSArray(array: tweetText!.componentsSeparatedByString(" "))
            var mailAddress = NSString()
            for var i = 0; i < words.count; i++ {
                var mailAdd = words.objectAtIndex(i) as!  NSString

                if mailAdd.rangeOfString("@gmail").location != NSNotFound {
                    NSLog("mail Address : %@", mailAdd)
                    if mailAdd.rangeOfString(".com").location == NSNotFound {
                        var lastChar = mailAdd.characterAtIndex(mailAdd.length-1)
                        var lastCharStr:NSString = NSString(format: "%ch", lastChar)

                        mailAddress = mailAdd.stringByAppendingString(".com")
                    }
                }
            }
        }


        return cell
    }        
}

同时线程1显示了这一点 http://i.stack.imgur.com/2YoQp.jpg (请仔细阅读此图片)

1 个答案:

答案 0 :(得分:0)

使用

moduleFor('controller:order', {
  needs: ['controller:orders']});

而不是

var cell = tableView.dequeueReusableCellWithIdentifier("placementID") as! PlacementsTableViewCell
if cell.isEqual(nil) {
    cell = PlacementsTableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "placementID")
}

并在其他帖子中更改下载图片,如关注

let cell = tableView.dequeueReusableCellWithIdentifier("placementID") as!  PlacementsTableViewCell