我有iPhone,我希望在显示AlertView
并且用户按下确定按钮后应该更改该视图但是没有发生。
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Thank you" message:@"" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
return;
[self moveToView];
-(void)moveToView
{
MainViewController*targetController=[[MainViewController alloc]init];
[self.navigationController pushViewController:targetController animated:YES];
}
答案 0 :(得分:7)
请使用UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// Code to move to next view
[self moveToView];
}
注意:在您的界面声明中实施UIAlertViewDelegate
。同时在声明UIAlertView时将委托设置为self。
希望这会对你有所帮助。
答案 1 :(得分:6)
简单。实现UIAlertViewDelegate并将代码放在那里。
- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
MainViewController*targetController=[[MainViewController alloc]init];
[self.navigationController pushViewController:targetController animated:YES];
[targetController release];
}
答案 2 :(得分:5)
@interface ClassName : ParentClassName <UIAlertViewDelegate>
<。>在.m中,添加此方法,
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
[self moveToView];
}
答案 3 :(得分:4)
实施警报视图的委托:
在yourClass.h文件中:
@interface yourClass : UIViewController<UIAlertViewDelegate>{
}
@end
在yourClass.m文件中:
@implementation yourClass
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
[self moveToView];
}
@end
答案 4 :(得分:3)
好吧,您将self设置为UIAlertView的委托。这是正确的,这是你必须采取的第一步。之后继续执行此方法:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[self moveToView];
}
您也可以在此处创建一个switch语句,以查看按下了哪个按钮。但由于您在AlertView上只有OK按钮,因此没有必要。
希望这有帮助。
干杯!
答案 5 :(得分:2)
使用- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
方法实施代码,并在类.h文件中添加UIAlertViewDelegate
。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"The index: %d",buttonIndex);
MainViewController*targetController=[[MainViewController alloc]init];
[self.navigationController pushViewController:targetController animated:YES];
[targetController release];
}
我认为这会对你有所帮助。