sending action to previosu view when using dismissModalViewController iphone - iphone

I am using presentModalViewController to display a view which allows the user to modify data that is being displayed in the first view. After the user has updated the data, I would like to send [tableView reloadData] to the first view.
Is that possible? Or is there a method I can create in the first view that gets called when the modalView is dismissed.

It should fit perfectly for your needs
Method for when the modal view has been dismissed
EDIT: syntax errors :)

Related

Manuel segue 'Show' does not call ViedDidload when returning to parent viewController?

I have a viewController containing a UITableViewController. This UITableViewController is populated by an array. When User presses populated cells they segue with a segue set to 'Manuel Segue : Show' this creates a back button UINavigation bar item. Inside this viewController the user is able to add Items to the array populating the parent UITableViewController. The problem is that when i segue back using the UINavigationbarItem it does not call viewDidload on the UITableViewController, there by not updating the UIViewTableCells. I have to close application to make it call viewDidload... How do i make it call ViewDidload when returning from the Manuel segue show? All help appreciated.
The pushing view controller is not unloaded when another view controller is shown above. As viewDidLoad: is only called once in the view lifecycle, this would then not be called when the segue is unwound.
Updating your tableview in viewWillAppear: or viewDidAppear: would cause this to be called whenever this view is displayed.
viewWillAppear would perhaps be better if you don't want to show the user the table reloading when not needing to asynchronously load data.
Read more on iOS view controller lifecycle here:
https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson4.html#//apple_ref/doc/uid/TP40015214-CH6-SW3

Xcode: Display Login View in applicationDidBecomeActive

In my app I would like to show a login screen - which will be displayed when the app starts and when the app becomes active. For reference, I am using storyboards, ARC and it is a tabbed bar application.
I therefore need to do the process in the applicationDidBecomeActive method:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
if ( ... ) { // if the user needs to login
PasswordViewController *passwordView = [[PasswordViewController alloc] init];
UIViewController *myView = self.window.rootViewController;
[myView presentModalViewController:passwordView animated:NO];
}
}
To an extent this does work - I can call a method in viewDidAppear which shows an alert view to allow the user to log in. However, this is undesirable and I would like to have a login text box and other ui elements. If I do not call my login method, nothing happens and the screen stays black, even though I have put a label and other elements on the view.
Does anyone know a way to resolve this? My passcode view is embedded in a Navigation Controller, but is detached from the main storyboard.
A variety of answers finally led me to an answer which doesn't seem too complicated so I will post it here - and it actually looks really good if I am honest.
Firstly, my password view is embedded in a Navigation Controller (Editor -> Embed In) and this is connected to the main tab bar controller using a modal segue with an id, in my case 'loginModal'.
In the applicationDidBecomeActive method put something like this:
[self performSelector:#selector(requestPasscode) withObject:nil afterDelay:0.2f];
And then put this function somewhere in the App Delegate
-(void)requestPasscode{
if ( /* If the user needs to login */ ) {
[self.window.rootViewController performSegueWithIdentifier:#"loginModal" sender:self];
}
}
This will present your login view whenever the app begins or enters the foreground (for example, when switching apps).
NOTE: The above line will not work if the root of your app is embedded in a navigation controller.
There are however two bugs;
If the user was previously viewing a modal view when they dismissed the app
If the user dismissed the app on the password view.
Both of these cause the app to crash so the following line goes in the applicationWillResignActive method.
[self.window.rootViewController dismissViewControllerAnimated:NO completion:nil];
It basically dismisses all modal views that are presented. This may not be ideal, but modal views are more often then not, used for data entry and so in many cases, this is a desired effect.
You should init PasswordViewController viewcontroller from xib or if you store UI in Storyboard you should use Segue for present this controller.
I can't say about another parts but that part seems to me very weird.
My passcode view is embedded in a Navigation Controller, but is detached from the main storyboard.
in storyboards you can store view controllers and view inside of view controllers so it's not good to store some view outside of viewcontroller because you will not be able to load this view from storyboard after receiving memory warning. Please correct me if I didn't get what do you mean.
If we are going by your way there is no difference load PasswordViewController at applicationDidBecomeActive or at your first view controller at Storyboards because you calling present view controller from first loaded view controller. So you can do it in your first view controller. Also you can store some hidden view inside of your first viewcontroller and show this view if the user needs to login.
I tested it. So at first your controller become loaded and then you got method applicationDidBecomeActive. So it's better to put your code inside -(void)viewDidAppear:animated method of your first viewcontroller.
Best regards,
Danil

refresh view in navigation controller

I am making an app where in if I tap on a cell of a table, I get navigated to another view. I am posting some data on that page but when I tap on the back button, the records are not updated. I understand it is because, I get the same view from the navigation controller. Can you suggest me a way to reload the data content in this case
In viewWillAppear:animated:, try this:
[tableView reloadData];

iPhone - possible to show a view from a modal view in the parent's view?

Hey guys, just wondering if this one is possible
I have an app that posts to tumblr, and the posting function is within a modal view of the main view. I have a connection listener that stops displaying an activity indicator in the status bar when the app gets a response from tumblr's servers. I want to display a message saying that it was posted successfully in the main window, outside of the modal view..is this possible?
Yes of course, you can add a subview to the UIWindow. In the app delegate make the window a property, if it isn't alreay. Now you can access the window with
((YourAppDelegate *)[[UIApplication sharedApplication] delegate]).window
Don't forget to cast, else window will give you a warning.
Adding a subview to the parentViewController while showing a modal view controller won't show it, it's behind the modal view controller.
Have you tried accessing the outside view via the parentViewController property on your modal view controller?

uitableview delegate methods are not called

I've got the problem that tableview methods are not called the first time the tableview is shown.
If I switch back to the previous view, and then click the button to show the tableview again, the methods are called this time.
I should say that I show an actionsheet while the tableview is loading.
The actionsheet I call in the ViewWillAppear method.
i fixed it by adding [self.tableView reloadData] after dismissing the actionsheet. i don't know if it's the proper way, but it somehow works.