7

UIAlertViewボタンを押すと が表示され、そのUIView中に 3 つのカスタム ボタンがあるアプリケーションを実行しようとしています。これまでのところ、すべてが機能します。3つのボタンの1つをクリックするUIImageViewと、画像を変更したいのですが、それもうまくいきます。問題は、アプリを起動しようとするたびに、どこからともなく sigabrt が発生していることです。

この行SIGABRTで私の中で起こりAppDelegate.mます:

self.window.rootViewController = self.viewController;

誰かが私を助けることができれば、それは素晴らしいことですが、私はxcodeとobjective-cにあまり慣れていないので、なぜこれが起こっているのかわかりません。

これが私のviewController.hです

#import UIKit/UIKit.h (i removed < > cause they were hiding everything inbetween in the post.)

@interface savingstatusViewController : UIViewController {

    UIView *loginView;
    UIImageView *statusImage;
    UIAlertView * MyTicketAlert;

}

- (IBAction)status:(id)sender;

@property (nonatomic, retain) IBOutlet UIView *loginView;    
@property (nonatomic, retain) IBOutlet UIImageView *statusImage;
@property (nonatomic, retain) IBOutlet UIAlertView * MyTicketAlert;

- (IBAction)green:(id)sender;
- (IBAction)yellow:(id)sender;
- (IBAction)red:(id)sender;

@end

これが私のviewController.mです

#import "savingstatusViewController.h"

@implementation savingstatusViewController

@synthesize loginView;
@synthesize statusImage,MyTicketAlert;

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

 #pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [self setLoginView:nil];
    [self setStatusImage:nil];
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

- (IBAction)status:(id)sender
{
    MyTicketAlert = [[UIAlertView alloc] initWithTitle:nil message:nil  delegate:self cancelButtonTitle:nil
                                     otherButtonTitles: nil];
    [MyTicketAlert addSubview:loginView];
    [MyTicketAlert show];
    MyTicketAlert.frame = CGRectMake(0, 1000, 440, 110);
}

- (IBAction)green:(id)sender 
{
    statusImage.image = [UIImage imageNamed:@"etat_controle.png"];

     [MyTicketAlert dismissWithClickedButtonIndex:0 animated:YES];
}

- (IBAction)yellow:(id)sender
 {
    statusImage.image = [UIImage imageNamed:@"etat_attention.png"];

     [MyTicketAlert dismissWithClickedButtonIndex:0 animated:YES];
}

- (IBAction)red:(id)sender
 {
    statusImage.image = [UIImage imageNamed:@"etat_danger.png"];

     [MyTicketAlert dismissWithClickedButtonIndex:0 animated:YES];
}

@end
4

3 に答える 3

5

UIWindow の rootViewController プロパティは、iOS4 より前には存在しません。iOS 3 以前のデバイスでこのコードを実行しようとすると、クラッシュします。

AppDelegate では、代わりに addSubview を使用できます。

//self.window.rootViewController = self.viewController; // Only iOS >= 4
[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];
return YES;
于 2011-07-06T14:21:20.243 に答える
4

これは、ファイルの所有者ビューが設定されていないか、正しく設定されていない場合にも発生します。ViewController.xib の File's Owner ビュー プロパティがビューに設定されていることを確認します。それを理解するのにしばらく時間がかかりました!

于 2011-08-13T14:07:49.750 に答える
2

MainWindow.xib の "TheNameOfYourProjetdelegate" に移動します。

「TheNameOfYourProjetdelegate」の「アウトレット」には、viewController が必要です。次に、「コントロール ドラッグ」をウィンドウに実行して、アプリケーションを実行します。

于 2011-04-06T22:36:05.567 に答える