[英]popViewController doesn't work with UIAlertView
I am having problem with AlertView. 我有AlertView问题。 I am trying to use the
UIAlertView
and after click ok it will return back to the previous screen but it do not seems to work any advice ? 我正在尝试使用
UIAlertView
,单击“确定”后,它将返回到上一个屏幕,但它似乎没有任何建议?
if (xGPSCoordinate==0 && yGPSCoordinate == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title"
message:@"Failed to load the to get your current location"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[alert show];
[alert release];
return;
[self.navigationController popViewControllerAnimated:YES];
}
or 要么
if (xGPSCoordinate==0 && yGPSCoordinate == 0) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"iPoly"
message:@"Failed to load the to get your current location"
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[alert show];
[alert release];
[self.navigationController popViewControllerAnimated:YES];
return;
}
both doesn't work 两者都不起作用
For this purpose you've to use UIAlertView
's delegate method. 为此,您必须使用
UIAlertView
的委托方法。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
First use this in your @interface
<UIAlertViewDelegate>
首先在
@interface
<UIAlertViewDelegate>
Then set the delegate, self.yourAlertView.delegate=self
; 然后设置委托
self.yourAlertView.delegate=self
;
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex==0)//first button which should be the OK button
{
[self.navigationController popViewControllerAnimated:YES];
}
}
use the delegate method of UIAlertView, see the answer given by iNoob. 使用UIAlertView的委托方法,请参阅iNoob给出的答案。 It does not make a sense if you write anything after the "return;"
如果在“返回”之后写任何内容,这是没有道理的; statement as the code below "return;"
声明为“返回”下面的代码; statement will never get executed.
语句将永远不会执行。
refer apple developer link for more details on UIAlertView delegate http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html 有关UIAlertView委托的更多详细信息,请参阅Apple开发人员链接http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html
or a simple tutorial on alert view http://mobile.tutsplus.com/tutorials/iphone/uialertview/ 或有关警报视图的简单教程http://mobile.tutsplus.com/tutorials/iphone/uialertview/
You just need to implement UIAlerView Delegate Methods. 您只需要实现UIAlerView委托方法。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{}
write your code for Pop to previous Controller here.You can the clicked button index and on the basis of that you can use.Don't for Conform UIAlertViewDelegate to Interface. 在此处将Pop的代码编写到上一个Controller。您可以单击按钮的索引并在此基础上使用。不要将UIAlertViewDelegate设置为Interface。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.