如何从UIalertview更改视图?

时间:2012-11-05 15:02:13

标签: ios uiview uiviewcontroller uialertview

请向我解释当我点击显示特定形式的UIalertView时如何更改UIView

类。 如果你知道任何教程,请不要犹豫

让我说当我收到特殊数据包时,我当前显示viewcontoller1然后我必须根据用户选择显示另一个xib

我在UIAlertView委托中尝试过pushViewController让它无法正常工作

1 个答案:

答案 0 :(得分:0)

使用UIAlertView代理。所以在你要调用的特定类中。在头文件中,像这样添加

@interface SomeClass : UIViewController <UIAlertViewDelegate> {
...

然后当警报为alloc / init时设置委托

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"title" message:@"message" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES", nil];
        [alert setDelegate:self];
        [alert show];

在与alertView相同的类中,将此委托方法放入。

-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if ([alertView cancelButtonIndex] == buttonIndex){
        return;
    //Do your UIView change here
}

希望这有帮助