0

I am working on a To-Do List App. I am using a tabbed application which has two tabs, One for "pending" tasks and other for "Done" tasks. Both the view controllers have UITableview. When the user taps on a task/cell in Pending Tasks tab, the task is considered done and it is shifted to the "Done" tasks tab. Can someone help me on how do I perform this operation.

I would really glad if someone can also help me with this task as well, As soon as the task is shifted to the Done task, How do I display a "Undo" button on the cell for 5 secs just like in gmail app when an email is deleted. Thanks in advance.

Devan
  • 7
  • 8
  • 2
    your basic probelm has been asked a lot of times already. did you tried to search ? And try to break your question in parts. Do not ask too much in one question. – Umair Afzal Sep 20 '16 at 10:58
  • Possible duplicate of [Passing data between View Controllers in Swift (From TableView to DetailViewController)](http://stackoverflow.com/questions/33643752/passing-data-between-view-controllers-in-swift-from-tableview-to-detailviewcont) – pedrouan Sep 20 '16 at 11:31
  • @UmairAfzal I tried searching, but couldn't find similar questions. – Devan Sep 20 '16 at 11:50
  • @pedrouan In the link you have given, the question is about passing data from tableview to other view controller, which I am familiar with. But, my problem is how do I completely shift the task from one VC to another. – Devan Sep 20 '16 at 11:51
  • Okay so what is your data sources for both tableView ? – Umair Afzal Sep 20 '16 at 11:51
  • @Devan Consider passing an array (of done/undone items) between those two view controllers and reloading the tableView at viewDidAppear in both controllers. – pedrouan Sep 20 '16 at 11:55
  • @UmairAfzal URL with JSON data. – Devan Sep 20 '16 at 11:59
  • @Devan you need to explain more. Lets say If you are poulating your pending and Done tableView from a webService. Then what you can Do is post JSON to server when user tap a call and then get the accurate data in Done TableView. – Umair Afzal Sep 20 '16 at 12:02
  • @UmairAfzal Sorry. I will download the data from JSON and using Coredata to store them in the device. Apart from that, User can also add some Tasks. – Devan Sep 20 '16 at 12:35

1 Answers1

0

In this case it's a matter of managing your data model. When you select the item in pending and it is considered complete, you update your data model to change that item to be completed from pending. Then you either reload the tableview or the row for the change to take affect in your tableview..

Azzaknight
  • 157
  • 1
  • 7
  • If you dont mind, can you please elaborate. I could not understand. – Devan Sep 20 '16 at 11:52
  • Yes, the data is stored to coredata and both the tableviews fetch data from Coredata – Devan Sep 20 '16 at 14:38
  • Excellent so both the tabs are getting the data from the same model. I take it the to-do model has an attribute which states whether it is completed or not and one tab displays data which is pending and the other tab displays the completed ones. So in the pending tab, when you press one of the to do item, mark the data as completed. This should be done in the tableviews didSelectRowAtIndexPath method. Then you reload the data and the one just marked as completed won't be displayed anymore. – Azzaknight Sep 20 '16 at 15:29
  • Thanks Azzaknight, I was really help full, Can you help me with the second path, on how to display undo button for 5 seconds. – Devan Sep 20 '16 at 15:38
  • Thinking about it - one way would be to have a Timer object in your controller. Also a button which is disabled by default on the table view cell. Then in the didSelectRowForIndexPath method - when the row is selected - you enable the button (maybe with undo written on it) and use the controllers timer object start a 5 second timer. On completion you do 3 things, disable the button, change the data and reload the tableview. Also set the target action for your undo button, in that you just cancel the timer and disable the button. – Azzaknight Sep 20 '16 at 15:59