Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios4 这张照片显示得很慢_Ios4_Uialertview - Fatal编程技术网

Ios4 这张照片显示得很慢

Ios4 这张照片显示得很慢,ios4,uialertview,Ios4,Uialertview,我刚刚编写了一个iOS应用程序来测试UIAlertView。当我运行它时,UIAlertView只是出现在屏幕上,没有UIAlertView的情况下屏幕先变暗,“很长一段时间”之后,UIAlertView出现了。这在模拟器和iPhone(IOS 4.2)上都会发生。我不知道为什么,请帮帮我,谢谢 说明:(您也可以下载该项目) 它是一个非常简单的基于视图的应用程序,有3个类:AppDelgate ViewControler和一个实现NSOperation的TestOperation; AppDel

我刚刚编写了一个iOS应用程序来测试UIAlertView。当我运行它时,UIAlertView只是出现在屏幕上,没有UIAlertView的情况下屏幕先变暗,“很长一段时间”之后,UIAlertView出现了。这在模拟器和iPhone(IOS 4.2)上都会发生。我不知道为什么,请帮帮我,谢谢

说明:(您也可以下载该项目)

它是一个非常简单的基于视图的应用程序,有3个类:AppDelgate ViewControler和一个实现NSOperation的TestOperation; AppDelegate只是XCode生成的一个; TestOperation.h:

#import <Foundation/Foundation.h>

@protocol TestOperationDelegate

- (void)didFinishTestOperaion;

@end


@interface TestOperation : NSOperation {
    id <TestOperationDelegate> delegate;
}

@property (nonatomic, assign) id <TestOperationDelegate> delegate;

@end
ViewContoller.m

- (void)viewDidLoad {
    [super viewDidLoad];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    TestOperation *testOperation = [[TestOperation alloc] init];
    testOperation.delegate = self;
    [queue addOperation:testOperation];
    [testOperation release];
}

- (void)didFinishTestOperaion {
    NSLog(@"start uialertview");
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Oops!" message:@"Here's the UIAlertView" 
                          delegate:self cancelButtonTitle:@"Confirm" otherButtonTitles:nil];
    [alert show];
    [alert release];
}
//已解决!!使用performSelectorOnMainThread使 在主线程上运行的UI


您试图在UIAlertView中测试什么?如果您只是从ViewDidDisplay调用UIAlertView:在您的ViewController中,UIAlertView是否按预期快速显示


我希望您遇到的问题与如何调用UIAlertView有关,并且UIAlertView是在ViewController控制的UIView出现之前显示的

解决了!!使用
performSelectorOnMainThread
使UI在主线程上运行

[alert performSelectorOnMainThread:@selector(show)with object:nil waitUntilDone:NO]


我在视图中添加了一个按钮,并将NSOperationQueue部分移动到事件侦听器内的触动按钮,以确保viewController已出现。当我触动该按钮时,UIAlertView的行为仍与以前相同。如果我只是从viewDidLoad调用UIAlertView,它的行为是正确的。因此我认为这可能只是因为我使用了代理,但我不知道如何解决这个问题。请在下面将您的解决方案作为答案发布,并在您能够这样做后接受它。
- (void)viewDidLoad {
    [super viewDidLoad];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    TestOperation *testOperation = [[TestOperation alloc] init];
    testOperation.delegate = self;
    [queue addOperation:testOperation];
    [testOperation release];
}

- (void)didFinishTestOperaion {
    NSLog(@"start uialertview");
    UIAlertView *alert = [[UIAlertView alloc]
                          initWithTitle:@"Oops!" message:@"Here's the UIAlertView" 
                          delegate:self cancelButtonTitle:@"Confirm" otherButtonTitles:nil];
    [alert show];
    [alert release];
}