i have an application in which i have implemented facebook in my app. In my app i have a page with a label and a button .when i click on the button the login page of facebook is opened.when i enter my username and password and click on the login button the login page dissapears. All this is working fine and but the problem is when i click again my button it should an alertview displaying that "this will logout from your previous account" and on the click of the ok button the session should get logged out displaying the login page.The problem is when i click the button it directly shows the login page without showing the alertview.Please help me in solving this problem.Thanks
Without seeing any of your code, i'm not too sure exactly how your logic is showing the alert, but if i was to show a confirmation alert, it would look something like this
- (IBAction)logoutButton_touchUpInside
{
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:#"Please Confirm"];
[alert setMessage:#"are you sure?"];
[alert setDelegate:self];
[alert addButtonWithTitle:#"Yes"];
[alert addButtonWithTitle:#"No"];
[alert show];
[alert release];
}
And implement the delegate method to catch the button click:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
// Yes, do something
}
else if (buttonIndex == 1)
{
// No, cancel etc...
}
}
Related
This question already exists:
Closed 10 years ago.
Possible Duplicate:
Create an alert on any view controller after Facebook request:didFailWithError:
I have a method that gets called if a video upload to Facebook has failed. If that method is called then I would like for a UIAlertView to appear in any view controller that a user happens to be on at the time the upload fails.
Is this possible?
UIAlertView creates it's own UIWindow above your application's main window and makes it key and visible. Any UIAlertView created by your application should be visible on any view controller in your application's main window.
-(void)yourMethod{
UIAlertView *alert = [[UIAlertView alloc] init];
[alert setTitle:#"Failed to upload video"];
[alert setMessage:#"bla bla bla"];
[alert setDelegate:self];
[alert addButtonWithTitle:#"Ok"];
[alert show];
}
then you can have this method to control what happens after the user clicks a button in your alert:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0 ){
//do something
}else if (buttonIndex == 1){
//if you add more buttons
//do something
}
}
if you have more alert-views, you could add a tag [alert setTag:(int)] to identify them in the -(void)alertView method with [alertView getTag]
I have an Iphone application in which when i am pressing a button it shows an alertview to chose the background.whichever background user is chosing will be played as the background of the audio clips.But now i need to add another alert before i am showing this alert for giving some warning.after that only i need to pop the second one.but i was done that chosing alert in the didappear of that viewcontroller and set it as a Uialertview delegate.and on the button actions i was doing different actions.Can anybody help me on achieving this?
proAlertView *loginav1=[[proAlertView alloc] initWithTitle:#"title" message:#"Choose a Background to play with this program?" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Field",#"Beach", #"Stars",nil];
[loginav1 setBackgroundColor:[UIColor colorWithRed:0.129 green:0.129 blue:0.129 alpha:1.0] withStrokeColor:[UIColor colorWithHue:0.625 saturation:0.0 brightness:0.8 alpha:0.8]];
[loginav1 show];
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
//[self play];
//moviePlayer.scalingMode=MPMovieScalingModeAspectFill;
if(actionSheet.tag==123)
{
[self backButtonPressed];
}
}
else if (buttonIndex == 1)
{
videoFile = [[NSBundle mainBundle] pathForResource:#"video-track" ofType:#"mp4"];
[self play];
moviePlayer.scalingMode=MPMovieScalingModeAspectFill;
}
how can i include another alert before this is my question?
Initialize first Alertview
UIAlertView *al1 = [[UIAlertView alloc] initWithTitle:#"Warning!" message:#"Warning Msg!!!" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles: nil];
al1.tag=1;
al1.delegate=self;
[al1 show];
Implement Delegate method
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(alertView.tag==1){
// implement button events for first Alertview
if(buttonIndex==1){
//First button clicked of first Alertview
UIAlertView *al2 = [[UIAlertView alloc] initWithTitle:#"Choose BG" message:#"Choose BG?" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"1",#"2",#"3", nil];
al2.tag=2;
al2.delegate=self;
[al2 show];
}
}
if(alertView.tag==2){
// implement button events for second Alertview
if(buttonIndex==1){
// First button clicked second Alertview.
}
}
}
Controller Class header
#interface ViewController : UIViewController<UIAlertViewDelegate>{
}
Hope this will fulfill your need !
You can do like this, first display warning message in alertview and when user click OK in alertview then in alertview delegate method write code to display second alertview where user can choose background.
I want to show nested alertViews. Problem, which i am facing in nested alertViews is that when i click an "add" button of first alertView it shows the second alertView, in second alertView i have a textField and a "Save" button. I want to save data when i click on save button and then reload UITableViewData, which is already in the first alertView.
I am new in iphone, so please help me.
You should create your alert views with different tag property so that in delegate method you can easily differentiate which alert view is appeared on the screen.
For example :
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"Info"
message:#"Message" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil] autorelease];
[alert setTag: 1001]; // give different tag to different alert views
[alert show];
[alert release];
Now in delegate method :
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alertView.tag == 1001)
{
// do something
}
eles if (alertView.tag == 1002)
{
}
}
Hope it helps you..
In Iphone I have to show an alert if the user clicks on home button immediately to indicate him that "The process will be stopped and he will loose the data".I have to tried to implement this using applicationWillResignActive and applicationDidEnterBackground.Can any one help me how can i achieve this?Is it appropriate to show such alert message on home button
Thanks,
Yogesh Chaudhari
Try this below code this will help you.
Its not really a way to quit the program, but a way to force people to quit.
UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:#"Hit Home Button to Exit" message:#"Tell em why they're quiting" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[anAlert show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
[[NSThread mainThread] exit]
}
}
I wish to know when the users are actually placing a call from my application (UIWebView) and not just tapping on the phone number.
How can I get the result of what the user selected when he receives the call/cancel popup after pressing a telephone link in my app?
There is some info regarding this on Opening tel: links from UIWebView.
How Things Work & What You Want
The OS is not going to handle showing the Call/Cancel alert dialog for you. That is up to you. It shows up in Safari because the Safari app's shouldStartLoadWithRequest method undoubtedly responds to the tel: scheme by showing a UIAlertView. Your conditional for if ([url.scheme isEqualToString:#"tel"]) should, when YES, trigger a UIAlertView with a Call and Cancel button. On Call, you will tell the sharedApplication to openURL; on Cancel, you will not issue the call & you will also want to return NO so your app does not attempt to loadWithRequest
Code Example:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 1) {
//OK clicked
} else {
}
}
- (void) _showAlert:(NSString*)title
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:#"Check your networking configuration." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
}
Hope this helped you in some way.
Best Regards
Linus