English 中文(简体)
1. 开放名称 来自其代表的观点再次未能在OS
原标题:Open an UIAlertView again from its own delegate fails in iOS

我有一个Pi,与一个UITextInput场和一个纽芬兰州开立了问答书。 当纽芬兰人要求使用代表方法时,应当对投入进行验证,并成功执行,或再次就失败发表《国际律师组织书》。

Now I reduced it to this litte test class with two UIAlertViews. It is always possible to open the other view but when I hit the button it asks for the screen remains empty.

#import "Yesorno.h"

@implementation Yesorno
@synthesize promptYES, promptNO;

- (id)init {
    self = [super init];
    if (self) {
        promptYES = [[UIAlertView alloc] init];
        [promptYES setDelegate:self];
        [promptYES setTitle:@"Press YES"];
        [promptYES addButtonWithTitle:@"YES"];
        [promptYES addButtonWithTitle:@"NO"];
        promptNO = [[UIAlertView alloc] init];
        [promptNO setDelegate:self];
        [promptNO setTitle:@"Press NO!"];
        [promptNO addButtonWithTitle:@"YES"];
        [promptNO addButtonWithTitle:@"NO"];
    }
    return self;
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0)
        [promptYES show];
    else
        [promptNO show];
}

@end

Edit: The AppDelegate. 现在确实是一个非常基本的申请,没有任何观点的控制者。

#import "AppDelegate.h"
#import "Yesorno.h"

@implementation AppDelegate

@synthesize window, yesorno;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window makeKeyAndVisible];
    yesorno = [[Yesorno alloc] init];
    [yesorno.promptYES show];
    return YES;
}

@end

我如何再次表明同样的辩词? 感谢。

最佳回答

您应采用<条码>didDismissWithButtonIndex 代表方法:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0)
        [promptYES show];
    else
        [promptNO show];
}
问题回答

您需要重新实施<条码>-(避免)alertView:AlertView * 点击的观点 ButtonAtIndex:NSInteger)buttonIndex: 代表方法。

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
     if(alertView == promptYES)
     {
        if (buttonIndex == 0)
          [promptYES show];
     }
     else if(alertView == promptNO)
     {
         if (buttonIndex == 0)
          [promptNO show];
     }
}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签