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.
Related
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!
So lets say there is a tableview and within that tableview each cell title and subtitle is loaded from Parse. How would I to make it so that once a cell is tapped and opened, it loads a view controller that has a navigation bar, picture, and text that is unique to that one cell. Each cell would have different text, pictures, and navigation bars, in which that data is loaded from Parse. Can pictures be stored on Parse and retrieved in-app?
I am working in swift. Feel free to ask me for any additional information. Thank you for your time! I appreciate any help!
If each individual cell will display the information related to one specific parse object, set it up so that your detail view controller has a parse object property and then when the user clicks a cell in the first view controller (the table), pass the parse object associated with that cell in prepareForSegue by setting the second view controller's parse object property to that specific object. By doing that, you can access all of that parse object's information in the second view controller through that property.
If the above is not the case, just make sure your second view controller has whatever properties it'll need so the relevant information needed to query Parse for whatever data you're trying to display can be accessed from your detail view controller.
Probably a bit hard to explain without diagrams but here goes.
Swift, iOS 8 using Storyboards.
I want to be able to load a view in the storyboard, load values into textfields, populate the TableView, etc. as if I was navigating to it normally but not actually showing the view to the user.
The view is an invoice template that I can capture and turn into a PDF but that relies on the fact that the view is populated with values, i.e. Loading the view.
I can call the PDF capture function without going to the view but the view is empty of values and table data. So far I've tried :-
let vc = storyboard?.instantiateViewControllerWithIdentifier("orderform") as OrderForm
vc.createPDFfromUIView(vc.view, aFilename: "test.pdf")
Thanks,
Anthony
Try setting
vc.view.hidden = true
before you present it.
I got it to work in the end. I had to move code that was in
viewDidLoad
to
ViewDidLayoutSubviews
on the OrderForm for the view to complete before taking a snap shot. Then the code below worked.
// Instatiate OrderForm viewController
let vc = storyboard?.instantiateViewControllerWithIdentifier("orderform")
as OrderForm
// Copy arrray items to OrderForm viewController for tableView data
vc.Orders = Orders
// Create PDF of OrderForm view using UIGraphicsBeginPDFContextToData
vc.createPDFfromUIView(vc.view, aFilename: "\(companyTextField.text).pdf")
// Call UIActivityViewController and attach PDF
share(sender)
Thanks,
Anthony
This is similar to my other question, but I was told to make a new question so no one get mad at me.
Ok so basically, I have a UITextView on on view controller, along with a save button. When the save button is tapped, I want the text of the UITextView to be saved to the plist. Then, on a totally separate view controller, I want a UITableView to display the saved files. Hope that makes sense.
Thanks in advance,
Tate
Can you load and save plist files?
If so, when the button is clicked, do this:
[myArray addObject:myTextView.text]; // myArray is an NSMutableArray
Then save the array to the plist. Next show the next view, which contains the table view. Then the next view can load the plist into another array.
I agree with another poster on your other question that this may not be the best design decision, but I can't see your code so I won't state that as fact.
To expand on this further:
IBAction button touchUp event...add text to array (if any)...save array to plist file...change the current view controller...on the viewDidLoad of the next view controller you load the plist file into another array...then use that array to populate the table view.
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?