I'd like to understand what's going on here. Basically I have a NumberOneViewController which owns a table view and is showing up on the details view controller on a split view based app.
When a user selects an entry on the NumberOneViewController tableview row, i assign the table view to RootViewController's tableView member like so:
self.tableView = numberOneViewController.tableView;
So the table view on the detail view controller is now gone - which brings me to my first question, what exactly happened here?
Now, I want number one view controller's table view again to show up on the details view controller, but how?
Maybe you need to reload/refresh the table view after you assign it. Just throwing out something off the top off my head since there are no other answers. Good Luck.
Related
I'm using a Master Detail View Controller with Swift.
When I click on a master cell, I see a collection view containing a list of pictures.
Each picture represent data stored inside Core Data.
Each picture data has also a timestamp and all picture taken the same day are stored in the same Master cell.
[Date of the day 1]
[pic1]
[pic2]
[Date of the day 2]
[pic3]
[pic4]
What I want to achieve is:
When I click on a picture, another ViewController is displayed (through a segue) and this new VC allows me to edit the picture and change its date.
The thing is I have multiple things happening here when I change the day or a picture:
if the pic was alone in the collection, then I also have to remove the Master Day cell too.
if the pic was not alone, I just need to update the detail collection view
In any cases, if I have to create a new Day, I need to create a new Master Cell and update the view and if I need to delete a Day, I have to also update the Master view.
If you edit the collection items, you can simply do a:
self.collectionView performBatchUpdates:
and then update the model, and notify the collection view of your action...
but I don't see how I can do that from another UIViewController.
Currently, in the Edit View Controller, I update the model and then dismiss the View controller. And I get a crash because the collectionView tries to display an Item that is not part of the current collection anymore...
To solve this issue, maybe I can use a protocol in order to inform the detail view from the edit view but If I do that, I need to give the IndexPath of the Edit Cell to the edit view and then give it back to the detail view through the protocol... Why not. but not that clean in my opinion.
Another problem is, the app seems to also crash in the master view when I delete a Day. Because, the master view doesn't know that I deleted a day from the edit view.
My main problem is that I don't see how to tell my Master View Controller that I made some model changes... especially when I don't have any IndexPath information from within the edit view.
Technically, I could use the notificationCenter to notify both Views, I guess... but still, I would need to pass both IndexPath from the Master view to the Detail view and then to the Edit view.
Ugly.
Several ways by which this can be achieved:
1) Delegation: The view controller containing collection view will act as a delegate of Edit View Controller and when editing is done it will callback a method to 'The view controller containing collection view'
2) Notification: EditingFinished
3) blocks
Using protocol is good solution but can be painful since you have to manage edited items using their indexPaths. A simpler solution, since you are using CoreData, is to fetch entries using a computed property and just call collectionView.reloadData() on viewWillAppear method from the controller that contains collectionView. This way calling reload data will recompute Core Data entries and will place each item in correct position. Also viewWillAppear will get called after dismissing controller that stands on top of collection view controller
I found an interesting article addressing my problem.
It was not indeed a trivial problem...
http://www.objc.io/issues/4-core-data/full-core-data-application/#using-a-collection-view
I am working on "implementing a search Bar"
When I work on "group table with multiple sections", Main.storyboard have View Controller and Table View it is run and display well like address list.
However, when I try to add the search Bar, I don't know how to deal with Main.storyboard. If I only have Table View Controller
I run it and display nothing.
If I have View Controller && Table View ,and also have Table View Controller, It have an error.
The code from the book is right, but to create Main.storyboard, the book explain very implicit.
By the way, what different between Table View Controller and use View Controller && Table View
The TableViewController comes with a tableView whose delegate and datasource are already set to be that TableViewController. This is normally used when it's ok for the table to take up the entire screen. The tableView is a normal view that you can add to any relevant ViewController. If this is the case, you must set its delegate and datasource and ensure that the corresponding ViewController conforms to UITableViewDelegate and UITableViewDataSource. The search bar would be a textField that would need a its delegate set. You can then write a search function to find whatever your text the user has in the textfield.
New to iOS programing and objective-c and am getting stuck on something which I am guessing is simple. Here's my question:
I have a simple, single view application with two text fields, a button and a table view. The idea is that I want to take the text from the two text fields and populate the next available cell in the tableview with this text. I've got everything sorted out except for how to update the contents of the table view on command. Ideally, I'd like the table view to be updated upon pressing the button.
I have a View Controller which is serving as the data source and delegate for the table view.
I am aware of the [tableView reloadData] method, but it requires the appropriate tableView variable within scope. This is fine in say a delegate method like tableView:didSelectRowAtIndexPath, and I've gotten it update upon selection of any cell, but what if I want to update the table view when an action unrelated to the table view is performed, say when the button is pressed? There is no tableView variable in scope of this method to call reloadData from (or is there)?
So I guess my question is: is there a way to access the table view variable from the rest of the view controller for the purpose of calling reloadData OR is there a method I'm not aware of that would facilitate this?
Thanks for any help!
Why do you you create an outlet for your table view in view controller?
Your view controller will be delegate and data source for the table view (you should set in interface builder or from code:
self.tableView.delegate = self;
self.tableView.dataSoure = self;
I am assuming that self.tableView - is the outlet that I mentioned. When ou have an outlet you can easily update table view after pressing the button: e.g you add new value to an array that is used for filling table view and call
[self.tableView reloadData];
If you do not want to reload all table you can use method insertRowsAtIndexPaths:withRowAnimation:
Actually you have to read next manuals as well:
https://developer.apple.com/library/ios/documentation/uikit/reference/UITableView_Class/Reference/Reference.html
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/tableview_iphone/AboutTableViewsiPhone/AboutTableViewsiPhone.html
This references are really useful.
I'm struggling with this problem, so I need your help. Basically I've programmed a complex table view controller (with NSFetchedResults protocol etc) and already used it in my app and it worked great. Since I want now exactly this table view inside another view (so I can add a small subview at the bottom of the screen), I'm really struggling how to do this! I know by know how to embed a simple table view inside another view and link it to it's view controller.
But how can I do this in my case with as little effort as possible? I mean can I somehow use this table view controller I already have even though the superview must have its own view controller?! And how would I do that? Sorry I'm still a beginner :)
Since you already have a TableViewController. To add it as an subview to another ViewController's (self) view, do this:
TVC = <your tableViewController instance>;
[self addChildViewController:TVC];
TVC.view.frame = <your desired frame>;
[self.view addSubview:TVC.view];
adding the TVC as childViewController will forward UI methods of 'self' like willAppear and all to TVC.
I have a view controller with a table view in it and several buttons. I would like to add an additional tableview on top of the view like this (or at least what it would look like if anybody wanted to be my friend :-)):
I don't want to just add this as a subview (like here or here)enter link description here since I don't want to check which table view is being used in my tableview delegate and datasource methods. I would rather use a separate view controller.
I don't want to use a picker because I need to display a bit of info with the items in the list.
I have no problem creating the view with the corresponding controller, but how do I add it on top of the current view, just hiding portions of it?
Thanks!
Apple has a sample code of TableView which deals with this issue. https://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html%23//apple_ref/doc/uid/DTS40010139
Above URL is the link to download the sample code from Apple developer library.
Hope it helps.
This might be overly simplistic for your application, but I have found it to be effective when I have had to do something similar.
You can add this 'drop down menu' view controller's view to the main UIWindow of the entire application. You can add a UIGestureRecognizer on the window as well. If the tap is outside of the view, make it fade away and remove it from the view hierarchy.
Initially I simply added logic in my tableview datasource and delegate methods to destingwish between the two tableviews (as suggested by Scott Bossak above. But I have since switched to building my two views in storyboard and adding their view controllers as usual. However, to present the second table view I instanciate it like so:
SecondTableViewContriller *secondTVC = [self.storyboard instanciateViewControllerWithIdentifier:#"secondTVC"];
then add it as a child view controller:
[self addChildViewController: secondVC];
[secondVC didMoveToParentViewController:self];
I then implemented a protocol to pass the information back to the parent view controller once a row has been selected.