f1rstsurf
f1rstsurf

Reputation: 647

Tableview automatically reload content

I'm facing a problem moving to a view from a tableview.

To explain the problem, i've got a view called myObjects which containing a tableview where are loaded some user objects, if the user tap on the cell a new view(objectConsult) is called with a modal segue.

In this view the user will find all informations about his object, when he tap on the back button which is linked with a modal segue too, he come back to myObjects.

My problem is, my tableview reloading cells each time i tap on the back button from objectConsul, i already succeed to block the reload in objective-C but in swift i don't understand what i have to do to solve the problem.

override func viewDidAppear(animated: Bool) {
             tableView.reloadData()
    }


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

    let cell:CustomCell = self.tableView.dequeueReusableCellWithIdentifier("Cell") as! CustomCell
    cell.picture.frame = CGRectMake(5,0,120,103)

    cell.title.text =  repos[indexPath.row].title

        let i = settings.ImagesCachedArray.indexOf({$0 == repos[indexPath.row].idobjet!})            
        let myImageName = "\(settings.ImagesCachedArray[i!]).png"            
        let imagePath = fileInDocumentsDirectory(myImageName)
        if let _ = self.loadImageFromPath(imagePath) {
            cell.picture.image = self.loadImageFromPath(imagePath)
        }
        else {
            let imgzeroresult = UIImage(contentsOfFile: NSBundle.mainBundle().pathForResource("noimage", ofType: "png")!)
            cell.picture.image = imgzeroresult
        }
}

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    performSegueWithIdentifier("mysegue", sender: self.view)
}

any help would be appreciated.

Upvotes: 0

Views: 2201

Answers (1)

the problem is:

override func viewDidAppear(animated: Bool) {
         tableView.reloadData()
}

change this method for viewDidLoad

override func viewDidLoad() {
         tableView.reloadData()
}

Upvotes: 3

Related Questions