Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.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/8/variables/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
Objective c UIAlertView仅在它之后显示';他被解雇了_Objective C_Ios_Uialertview - Fatal编程技术网

Objective c UIAlertView仅在它之后显示';他被解雇了

Objective c UIAlertView仅在它之后显示';他被解雇了,objective-c,ios,uialertview,Objective C,Ios,Uialertview,我已经花了两天的时间试图解决这个问题,在任何人发布另一个stackoverflow问题之前,我已经阅读了所有这些问题,但没有一个完全涵盖了我的问题: 我有一个动态更新的CoreData应用程序。现在,在更新过程中,我希望弹出一个UIAlertView,说明正在下载更新 下面是重要的代码: AppDelegate: - (void)applicationDidBecomeActive:(UIApplication *)application { [myUpdater checkForUp

我已经花了两天的时间试图解决这个问题,在任何人发布另一个stackoverflow问题之前,我已经阅读了所有这些问题,但没有一个完全涵盖了我的问题:

我有一个动态更新的CoreData应用程序。现在,在更新过程中,我希望弹出一个UIAlertView,说明正在下载更新

下面是重要的代码:

AppDelegate:

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [myUpdater checkForUpdatesInContext:self.managedObjectContext];    
}
_

这是调用
[super viewDidLoad]
的正确位置吗?因为它仍然不能像这样工作,所以在屏幕上显示启动图像时仍在进行更新:-((我要放弃这一个.

你正在做一个:

- (void)applicationDidBecomeActive:(UIApplication *)application
您要显示的alertview是否需要加载一个此时尚未激活的视图?请参阅:


类似的问题?

您正在启动后台线程,然后立即解除警报。我建议您可以使用从后台任务发布并在启动警报的任何控制器中接收的
NSNotification
,触发解除警报的方法


我发现
UIAlertView
界面不适合这种类型的用户通知,我更喜欢使用半透明的覆盖视图,带有
UIActivityIndicatorView
,并为用户提供一条通知消息。

在这个原型中,事情完全按照您希望的方式工作

标题:

#import <UIKit/UIKit.h>

@interface AlertViewProtoViewController : UIViewController
{

}

- (void) showAlertViewWithTitle:(NSString *)title;
- (void) checkForUpdatesInContext;
- (void) update;
- (void)someMethod;
- (void)someOtherMethod;

@end

#import "AlertViewProtoViewController.h"
#导入
@接口AlertViewProtoViewController:UIViewController
{
}
-(无效)showAlertViewWithTitle:(NSString*)标题;
-(void)检查文本中的更新;
-(b)更新;
-(无效)某种方法;
-(无效)其他方法;
@结束
#导入“AlertViewProtoViewController.h”
类别:

@implementation AlertViewProtoViewController

UIAlertView *alertView;
bool updateDone;
UILabel *test;
bool timershizzle;

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.view.backgroundColor = [UIColor yellowColor];

    UILabel *test = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
    test.backgroundColor = [UIColor blueColor];
    [self.view addSubview:test];

    [self performSelector:@selector(checkForUpdatesInContext) withObject:nil afterDelay:0.0];
}


- (void)update
{
    //NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //commented for auto ref counting
    NSLog(@"update start");
    //your update stuff
    NSLog(@"update end");
    updateDone = YES;
    //[pool release];
}

- (void)checkForUpdatesInContext//:(NSManagedObjectContext *)myManagedObjectContext
{
    //[self loadUpdateTime];

    NSLog(@"Update start");

    NSDate *now = [NSDate dateWithTimeIntervalSinceNow:[[NSTimeZone localTimeZone] secondsFromGMT]];
    //    if ([now timeIntervalSinceDate:updateTime] < UPDATE_TIME_INTERVAL)
    //    {
    //        return;
    //    }
    [self showAlertViewWithTitle:@"Update"];
    //[self setManagedObjectContext:myManagedObjectContext];

    [self performSelector:@selector(someMethod) withObject:nil afterDelay:0.0];

    [self performSelector:@selector(someOtherMethod) withObject:nil afterDelay:0.0];
}

-(void)someOtherMethod
{
    while (!updateDone) {
        //        NSLog(@"waiting...");
    }

    [alertView dismissWithClickedButtonIndex:0 animated:YES];
    NSLog (@"Update done");
    self.view.backgroundColor = [UIColor greenColor];
}

-(void)someMethod
{
    [self performSelectorInBackground:@selector(update) withObject:nil];
}

- (void) showAlertViewWithTitle:(NSString *)title
{
    alertView = [[UIAlertView alloc] initWithTitle:title message:@"Daten werden aktualisiert..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    alertView.frame = CGRectMake(100, 100, 200, 200);
    alertView.backgroundColor = [UIColor whiteColor];

    [self.view addSubview:alertView];

    [self.view setNeedsDisplay];

    NSLog (@"AlertView shows");
}

@end
@实现AlertViewProtoViewController
UIAlertView*alertView;
布尔更新酮;
UILabel*试验;
bool timershizzle;
#pragma标记-视图生命周期
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
self.view.backgroundColor=[UIColor yellowColor];
UILabel*test=[[UILabel alloc]initWithFrame:CGRectMake(0,0500500)];
test.backgroundColor=[UIColor blueColor];
[self.view addSubview:test];
[self-performSelector:@selector(checkForUpdatesInContext),对象:nil afterDelay:0.0];
}
-(作废)更新
{
//NSAutoreleasePool*pool=[[NSAutoreleasePool alloc]init];//对自动引用计数进行了注释
NSLog(@“更新启动”);
//你的更新资料
NSLog(@“更新结束”);
UpdateOne=是;
//[池释放];
}
-(void)checkForUpdatesInContext/:(NSManagedObjectContext*)myManagedObjectContext
{
//[自加载更新时间];
NSLog(@“更新启动”);
NSDate*now=[NSDate DATE WITH TIMEINTERVALICENSNOW:[NSTimeZone localTimeZone]秒自GMT];
//如果([now timeIntervalSinceDate:updateTime]

您应该根据自己的需要进行调整,但它可以工作。

更新过程是否在单独的线程中运行?不,所有内容都在其中运行。我希望用户在更新过程中不能执行任何操作,因此UIAlertView我想这就是您遇到问题的地方。嗯,我想我以前尝试过。让我来看看c更改我的代码,我会发布一个编辑,看看这是否是你的意思。如果我添加BOOL,它又回到了原来的行为,但我认为Totumus Maximus发现了问题。由于我使用ApplicationIDBecMeasive,没有视图可以显示UIAlertView,因此它实际上正在显示,但用户还看不到它,因为在上没有视图这个屏幕听起来不错。你知道有没有办法解决这个问题吗?问题是:我想定期检查更新,在更新方法中,我检查是否已经过了一天。所以我想我把更新检查放进了DidBecomeActive方法中,这样每次用户打开a时都会调用它pp(再次或从头开始)关于类似的问题,它是正确的/“相同”问题,但显然我在这里处理的是一个视图问题,因为DidBecomeActive方法。既然你想在更新过程中显示alertview,我会将整个函数放在viewdidload方法中。每次重新启动应用程序时,你都会回到同一个视图问题。在你的情况下,你可以在你的spl之间创建一个视图ash和你的主应用程序来解决这个问题。你可以让它与你的splashscreen具有相同的背景,这样用户就不会注意到它们之间的差异。当这个中间视图加载后,你可以安全地显示你的alertview。嗯……这也是我的想法,所以我尝试将更新放在我的屏幕上显示的第一个视图控制器中tabbarcontroller和我将其放入
viewDidLoad
方法中,但在启动映像期间更新仍在运行,并且不会在其他任何地方调用它,因为如果我对该调用进行注释
#import <UIKit/UIKit.h>

@interface AlertViewProtoViewController : UIViewController
{

}

- (void) showAlertViewWithTitle:(NSString *)title;
- (void) checkForUpdatesInContext;
- (void) update;
- (void)someMethod;
- (void)someOtherMethod;

@end

#import "AlertViewProtoViewController.h"
@implementation AlertViewProtoViewController

UIAlertView *alertView;
bool updateDone;
UILabel *test;
bool timershizzle;

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.view.backgroundColor = [UIColor yellowColor];

    UILabel *test = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
    test.backgroundColor = [UIColor blueColor];
    [self.view addSubview:test];

    [self performSelector:@selector(checkForUpdatesInContext) withObject:nil afterDelay:0.0];
}


- (void)update
{
    //NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //commented for auto ref counting
    NSLog(@"update start");
    //your update stuff
    NSLog(@"update end");
    updateDone = YES;
    //[pool release];
}

- (void)checkForUpdatesInContext//:(NSManagedObjectContext *)myManagedObjectContext
{
    //[self loadUpdateTime];

    NSLog(@"Update start");

    NSDate *now = [NSDate dateWithTimeIntervalSinceNow:[[NSTimeZone localTimeZone] secondsFromGMT]];
    //    if ([now timeIntervalSinceDate:updateTime] < UPDATE_TIME_INTERVAL)
    //    {
    //        return;
    //    }
    [self showAlertViewWithTitle:@"Update"];
    //[self setManagedObjectContext:myManagedObjectContext];

    [self performSelector:@selector(someMethod) withObject:nil afterDelay:0.0];

    [self performSelector:@selector(someOtherMethod) withObject:nil afterDelay:0.0];
}

-(void)someOtherMethod
{
    while (!updateDone) {
        //        NSLog(@"waiting...");
    }

    [alertView dismissWithClickedButtonIndex:0 animated:YES];
    NSLog (@"Update done");
    self.view.backgroundColor = [UIColor greenColor];
}

-(void)someMethod
{
    [self performSelectorInBackground:@selector(update) withObject:nil];
}

- (void) showAlertViewWithTitle:(NSString *)title
{
    alertView = [[UIAlertView alloc] initWithTitle:title message:@"Daten werden aktualisiert..." delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    alertView.frame = CGRectMake(100, 100, 200, 200);
    alertView.backgroundColor = [UIColor whiteColor];

    [self.view addSubview:alertView];

    [self.view setNeedsDisplay];

    NSLog (@"AlertView shows");
}

@end