I am using an NSFetchedResultsController with my tableview inside of a UINavigationControler. When an item is tapped on the tableview I perform a 'push' and pass a specific entity in the prepareForSegue in order to show more detailed data about that record.
In the detail view controller the model can be edited. There appears to be a lot of lag when I change the model. And I noticed that the tableView:cellforRowAtIndexPath: on the previous view controller is being called.
I've tried using performSelectorInBackground: but doesn't seem to help much.
Once push a view controller, isn't the view controller below not supposed to run? Has anyone been able to overcome this lag issue?
Thank you
I actually ran into this tonight and solved it by adding a new bool property on my view controller to store when my VC is visible.
#property (nonatomic, assign, getter = isVisble) BOOL visible;
Then I check at the top of FRC delegate methods if the view is visible or not.
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
if (! self.isVisble) {
return;
}
[tableView beginUpdates];
}
This seems to help stuttering and performance when the VC with the FRC has been pushed behind other VCs.
Related
I have found a few other questions about this same topic, so this is technically a repost, however the solutions provided there are not helping me at all. The solutions that have been suggested, which seem to work for the other users, are already present in my code.
Here is the code that is causing me problems.
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
let navView = segue.destinationViewController as UINavigationController
let destinationView = navView.topViewController as DetailViewController
And here is the error I am getting:
fatal error: unexpectedly found nil while unwrapping an Optional value
The error is thrown on the error where I am accessing navView.topViewController.
I have a table view segueing to a navigation controller, which then segues to my own custom view controller under it. I want to pass data to my custom view controller from the table view.
I had it working fine earlier today before adding the navigation controller in between, passing data directly from the table view to the navigation controller. Adding the navigation controller in between has broken things.
Are there any suggestions as to why I am having this problem? The only thing I can think is that the DetailViewController hasn't instantiated yet since it is two levels deep now. But then if that is the case, I don't know why it seems to be working for other people.
I have a table view segueing to a navigation controller, which then segues to my own custom view controller under it.
I believe that is your problem. The connection from the Navigation Controller to your Detail View Controller isn't a normal segue. It should be a Relationship Segue.
Click on the connection between the Navigation Controller and the Detail View Controller. Press delete.
Control-drag from the Navigation Controller to the Detail View Controller and select root view controller from the pop up.
Now navView.topViewController will be non-nil.
I want to print a NSString in my TextView in the mainViewController. But this command should come from a second ViewController. I declared a string in my mainViewController.h but I need this string in secondViewController.m! (The text should be printed in mainViewController). When I want to access to this string, it says Xcode does not know this variable. How can i create a string/variable, which I can edit and print from all of my ViewControllers(xib!)?
It sounds like you want to share a model between two view controllers. This is the correct MVC approach so that all that is required is for one of the view controller to change the value in the model and all the other view controllers will be notified and can update their respective views:
Please look at this excellent article on how this should be implemented.
just declare that NSString variable in AppDelegate & access in any ViewController through the sharedApplication method .in your case assign value to it in secondViewController & access that value in mainViewController
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSLOg(#"Nsstring value=%#",appDelegate.stringVariable);
assigning value:appDelegate.stringVariable=#"fromSecondViewController");
i am creating my first app.i have multiple view controller stack in my app. i want to switch view controllers, so i am using this method:
wallViewController *dvc = [[wallViewController alloc] initWithNibName:#"wallViewController" bundle:nil];
dvc.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:dvc animated:YES];
[dvc release];
its working fine. but its reloading view controller,like its calling viewdidload each time,but i want to show the previous state of parent view controller as in navigation controller.Please help me.
Im going to a new view using the following code:
UIStoryboard *storyboard = self.storyboard;
finishViewController *finished = [storyboard instantiateViewControllerWithIdentifier:#"finishViewController"];
[self presentViewController:finished animated:NO completion:nil];
Once the new view is loaded the previous view controller is still functioning behind it. Is there a way I can erase it from memory?
Ive tried:
[self.presentingViewController dismissModalViewControllerAnimated:YES];
and
[self.parentViewController dismissModalViewControllerAnimated:YES];
I thought this would be pretty straight forward. T
Thanks
You're presenting a modal view from the parent view controller.
It sounds like what you really want to do is push or segue the finished view controller from the parent view controller.
If you are determined to dismiss / erase the parent view controller, why not first pop the parent view controller and then push/present the finished view controller.
Try using [finished makeKeyAndVisible] it'll make your new controller the only controller.
This can't be done. If you dismiss the parent you'll dismiss both of them.
I've developed an app for Mac OS X Lion using its new view-based NSTableView, but as I want to port the whole app to Snow Leopard I'm trying to figure out the best way to emulate such a tableview. So far I've created a NSCollectionView and everything is fine, except for the fact that I can't get the index of the view from which a button click event is triggered.
In Lion I have the following function:
- (IBAction)buttonClick:(id)sender
so I can get the index of the view inside the tableview using a method (I can't remember its name) like
- (NSInteger)rowForView:(NSView *)aView
with aView being the sender's superview, but I couldn't find something similar for the collection view ... The only "useful" method seems to be
- (NSCollectionViewItem *)itemAtIndex:(NSUInteger)index
(or something like this), but this can't help me as it returns a NSCollectionViewItem and I can't even access it knowing only the corresponding view!
Within buttonClick, try this code:
id collectionViewItem = [sender superview];
NSInteger index = [[collectionView subviews] indexOfObject:collectionViewItem];
return index;
Hope this helps :)
Geesh! Both of those approaches have issues. I can see how the first on may work, but note that the "collectionViewItem" is actually the view, NOT the collectionViewItem, which is a view controller.
The second way will not work, unless you subclass the button and put in a back link to the collectionViewItem. Otherwise, your view does not know what collectionViewItem controls it. You should use a selector binding to the collectionViewItem's representedObject instead, to get the action to the correct object in your array.
How about something like:
id obj = [collectonViewItem representedObject];
NSInteger index = [[collectionView contents] indexOfObject:obj];
As I suggested here: How to handle a button click from NSCollectionView
I would do it like this (because the button you want to press should be coupled with the corresponding model, therefore the represented object):
Add a method to the model of your collectionViewItem (e.g. buttonClicked)
Bind the Button Target to Collection View Item
While binding set model key path to: representedObject
While binding set selectorname to: methodname you chose earlier (e.g. buttonClicked)
Add protocol to your model, if you must tell delegate or establish observer-pattern
use NSArrayController for binding to NSCollectionView,
use collectonViewItem.representedObject to get a Custom Model defined by yourself.
save and get index in your custom model.
That's works for me.