Swift: Want to add value to NSTableView(1st ViewController) from secondViewController - swift

so I have been able to use delegates and protocols to pass data from secondViewController to the firstViewController. Till now I have been showing data as a label in the 1stVC. Now I want to add it to NSTableView.
I am finding it a bit hard to get the hang of TableView. Basically I am using the variable (data) that stores the values/string inserted in the secondViewController. I imagine, I use the data variable to show it on TableView?
I want the delete button to be on the firstViewController, so essentially you can delete the value from the firstViewController but can only insert it from the secondVC.
Anyone here who can help me with the code both for tableView & adding data to the row!

Related

Swift Communicating between view controllers

I'm new to Swift and was wondering how I could set up segues between three view controllers. What I'm thinking is that the first viewController allows the user to choose between 2 objects, than redirects to secondView which allows to choose between 22 objects and based on the combination of the user's past 2 view controller choices, a new tableView is created. How can I trace the user's decisions and provide a tableView related to that in such a program? Thank you very much in advance.
I have Two rough solution for you.
(Not recommended) use two global variables VcOne and VcTwo. while selecting first object put a value in VcOne and when selecting from second 22 objects put value in VcTwo. and in tableView's Controller check both the variables and create your table View.
While performing Segue, have a Variable in destination ViewController and put a identifier. and have two variables on the Third ViewController. when you perform segue from second ViewController, assign Identifier of previous ViewController and current View Controller to next controller's Variables. and in tableView's Controller check both the variables and create your table View.
You can also use a array to keep track of user's selection.
Those are very basics of iOS development. just split the tasks that you need to do.
First split steps you have to do. First study about the navigation between View Controllers. in your case using segue. There are lots of questions regarding that in stack overflow.
then find out how to pass data between viewControllers. once you know about navigation it is very easy.
You can create logic with the values you are passing recieving.
ex: firstViewController will pass parameter called objectCount to secondViewcontroller. and based on that value count you can decide what are objects should show hidden.
And then based on that selection you need to get Object back to the firstViewController or go to another 3rd View Controller.
I'm really sorry but I don't think you can start developing iPhone application without understanding the basics.
You will need three ViewControllers and you need to use parepare(for:sender:) method to pass the data from one ViewController to another ViewController.
Here is an example on how to pass data between ViewControllers.

Edit and add button for UITableView in ViewController

I have a little problem, I want to add a function to two BarItems in my UINavigationBar, which is placed above the UITableView in a normal ViewController. I'm very new to programming so can you please give me the complete code that I need? The functions I want to have are:
An edit button so I can delete and change the data of a cell (title + subtitle)
An add button so I can add a new cell to my UITableView. Maybe also a function that points to another ViewController where I can type the data for Title and subtitle to save it afterwards.
Thanks!
For editing record:
You cannot get the cell that your planning to edit using button on UINavigationController, the buttons should be placed at the same cell on your UITableview to edit that specific cell. and in this way you need custom UITableviewcell.
For creating new record :
First link the button to your UIViewController class as Action.
You can append the array that your using to fill the UITableview and then call your UITableview like to refresh the data:
self.tableview.reloadData()
For presenting another UIViewController:
First drag new ViewController in your storyboard and link the button on the first ViewController into your new UIViewController and choose segue as "Show".
To save your data its a big topic you have either NSUserDefaults or CoreData so Google it.
Note : linking means by pressing ctrl-drag with mouse to your target.
Update :
Download your sample from here : https://yadi.sk/d/EJf610XWhkxDT

Pass plist Data from TableView in labels of another View

I try to make an app that shows Data from a plist in a tableView and when clicked pass that data to the ViewController using prepareForSegue.
I could set up the plist data appearing in the tableViewCell with cell.textLabel.textand cell.detailTextLabel.text. But until now, I was not able to get a working Segue.
How do I use prepareForSegue in order to pass over the Title and Subtitle of the Cell plus other Data that is located in the plist.
Thanks for any answer.
Use #property and #synthize for do it.
You can have a look here where there is a good explanation.

TableView is not showing data?

I have place this question before on following link with code & screenshot.
TableView is not loading data?
Now I came to know my tableview is loading data in tableview cell but not showing/displaying it. I have one Model View Controller in my project. The ModelView controller get called from Mapviewcontroller screen through Search Button. After resigning the Model view controller I can see the data in tableview. (It means when I move to next controller and back to previous tableview.. my tableview shows data in it.)
Here I my data get visible in tableview only after resigning the modelview controller.....
Everything works fine. I just want to know how should I display the tableview data as soon as web-service get called on first screen itself???
Put [_tableView reloadData]; at the end of the method that calls the web-service, or the one that populates the markers array.
If you are manipulating table data in an asynchronous Block,
pass a reference of the tableview to the method implementing the block, and remember to call
[tableview reloadData];
within the block, and not out outside

iPhone - UITableViewController and Core Data rows repeating in tableView

I am new to Cocoa and Core Data and I've encountered a weird problem. I successfully created the Core Data model, imported the data, made the UI (Navigation controller, tableViewController with searcDdisplayController) but now I'm stuck at one problem. If I implement a UITableViewController (with no UITableView in the nib file), the results fetched from fetchedResultsController are weird - the row count is correct (500 rows), but they are repeating themselves - only 8 different rows.
However, I was able to fix this problem by adding #synthesize tableView; in the .m file.
Then i encountered another problem - when i click on a row and push the details view, then click the back button on the Navigation Controller, the selected row in the tableView is still selected.
I hope I am being clear on what's wrong. Let me recap:
If I don't put the #synthesize tableView; on the top of the implementation file, the deselection of the row is working fine, but the results are wrong - 8 rows (out of 500) repeating in the tableView.
If I put the #synthesize in the file, the data in the tableView is correct, but there is no animation when i get back to the tableView with the navigation controller.
I also tried to put a UITableView in the nib file of the listviewcontroller, but the results were the same - no deselection of the row. I also tried to deselect row in the viewWillAppear delegate, but the indexPath of the indexPathForSelectedRow is null.
Oh, and I'm using an NSFetchedResultsController. Like I said - the fetched results are correct, but it seems that they're not properly fed to the tableview (if it is not synthesized..)
Thanks!
I might be able to solve your row highlighting issue but you will need to include some code examples so we can help you with the other items...
To deselect a row you can call the method [deselectRowAtIndexPath:animated:] this will allow you to deselect the row before or after you push your detail view controller from your tableView selection delegate. Table View Reference
Thanks for responding!
Hmm..I may have found a solution, but I'm not sure it's correct.. I am implementing the UITableViewController in my new class, but I'm actually using a new UITableView (tableView2) for the data fetching. In the nib file i created the UITableViewController, set the Class name to my custom class BUT I didn't connect the Table View in the Interface Builder with my newly created tableView2. I hope you'll be able to understand.. It's quite complicated, this whole stuff :S
So if I get this right - if I implement an UITableViewController, my class automatically gets a self.tableView? But, like I said in my question, if I don't synthesize the property in the .m file, the controller can't deselect the row automatically..but if I do, the data isn't correct and is repeating..Maybe there is a problem in the cellForRowAtIndexPath, where i get my cells from self.tableView..but It's not logical :S
Anyway, now the row de-selection animation works without my interference and the data displayed is correct. I'm suspecting that the UITableViewController has some other methods that need to be overwritten if using the NSFetchedResultsController.
Do you think my method is incorrect? Having a new UITableView in my custom UITableViewController class?