第一个ios应用程序给空白的白色屏幕

时间:2014-04-25 06:48:18

标签: ios objective-c

我最初在iphone上运行时会出现黑屏。当我从我的Mac断开iphone并打开应用程序时,会打开一个普通的白屏。请帮助。

BNRQuizTableViewController.h

#import <UIKit/UIKit.h>
#import "BNRQuizTableViewController.h"


@interface BNRQuizTableViewController : UITableViewController

@end

BNRQuizTableViewController.m

#import "BNRQuizTableViewController.h"

@interface BNRQuizTableViewController ()

@property (nonatomic) int currentQuestionIndex;

@property (nonatomic, copy) NSArray *questions;
@property (nonatomic, copy) NSArray *answers;

@property (nonatomic,weak) IBOutlet UILabel *questionLabel;
@property (nonatomic,weak) IBOutlet UILabel *answerLabel;

@end

@implementation BNRQuizTableViewController
-(IBAction)showQuestion:(id)sender
{
 {
    // Step to the next question
    self.currentQuestionIndex++;

    // Am I past the last question?
    if (self.currentQuestionIndex == [self.questions count])
    {

        // Go back to the first question
        self.currentQuestionIndex = 0;
    }

    // Get the string at that index in the questions array
    NSString *question = self.questions[self.currentQuestionIndex];

    // Display the string in the question label
    self.questionLabel.text = question;
    self.answerLabel.text=@"???";
 }
}

-(IBAction)showAnswer:(id)sender
{
 {
    // What is the answer to the current question?
    NSString *answer = self.answers[self.currentQuestionIndex];

    // Display it in the answer label
    self.answerLabel.text = answer;
 }

}



- (instancetype)initWithNibName:(NSString *)nibNameOrNil
                     bundle:(NSBundle *)nibBundleOrNil
{
// Call the init method implemented by the superclass
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

if (self)
 {
    // Create two arrays filled with questions and answers
    // and make the pointers point to them

    self.questions = @[@"What is the name of the first prophet?",
                       @"What is the name of the last prophet",
                       @"Who was the first caliph ?"];

    self.answers = @[@"Prophet Adam(A.S)",
                     @"Propher Mohammed(S.A.W)",
                     @"Hazrat Abu bakar"];
 }

// Return the address of the new object
return self;
}


@end;

BNRAppDelegate.h

#import <UIKit/UIKit.h>

@interface BNRAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

BNRAppdelegate.m

#import "BNRAppDelegate.h"
#import "BNRQuizTableViewController.h"



@implementation BNRAppDelegate



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:   (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

BNRQuizTableViewController *quizvc = [[BNRQuizTableViewController alloc]init];
self.window.rootViewController=quizvc;


self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

@end

1 个答案:

答案 0 :(得分:0)

您需要使用initWithNibName:bundle:为视图控制器指定nib名称,否则视图控制器将没有分配有效视图:

BNRQuizTableViewController *quizvc = [[BNRQuizTableViewController alloc] initWithNibName@"YOUR_NIB_NAME_HERE" bundle:[NSBundle mainBundle]];