Search code examples
objective-cnstimernsindexpath

UITableView problem with NSIndexPath


I got a tableview with guests(VM's) which i can turn on/off/reboot, this works perfectly when i do it on 1 Guest.. but when i try to do in 2+ guests at the same time the table responds very bad and the app crashes when i try to do something, what it basicly does is when i click on a row i get the choose what i want to do with it turn in on/off or reboot. i have got an NSTimer which checks every second if the VM has been succesfully completed in the function it self i got the variable selectedindexPathForTheGuest so the row updates itself when its completed but as i say when i try to do 2 or more at the sametime this variable gets overwritten by the last rowindexnumber that i call.. so then when a task is completed is updates the last selected row instead of the row it supposes to..

How can i prefent this from doing so?

(im probally making a beginner mistake as im actualy an beginner..)


Solution

  • You should look into the delegate Pattern instead of setting a variable.

    Maybe something like this would work for you

    • When the user selects an action launch a new thread to perform it
    • The new thread monitors the activity of the selected VM
    • When the VM finishes the action you can call [tableView reloadData]