2011-06-12 6 views
4

내비게이션 컨트롤러가있는 iOS 앱을 쓰고 있습니다. 시뮬레이터에서 열면 잘 돌아갑니다. 장치에서 실행하면 빈 화면이 상태 표시 줄 아래에 표시됩니다. 게다가 내 RootViewController가 기본 뷰 (내 문제의 근원이라고 생각되는)로 만들어 졌는지 알 수 없습니다.장치의 빈 화면; 시뮬레이터가 잘 작동합니다.

@class RootViewController; 

@interface MyAppDelegate : NSObject <UIApplicationDelegate> { 
    UIWindow *window; 
    RootViewController *viewController; 

    UINavigationController *navigationController; 
} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 
@property (nonatomic, retain) IBOutlet RootViewController *viewController; 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

    // Override point for customization after application launch. 

    // Set the navigation controller as the window's root view controller and display. 
    self.window.rootViewController = self.navigationController; 
    [self.window makeKeyAndVisible]; 

    // ... 

    return YES; 
} 

RootViewController.m

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.title = @"Main Menu"; 
} 

등 없음 viewWillAppear, viewDidAppear,

0 표시 소자 테이블.

- (UITableViewCell *)tableView:(UITableView *)tv 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    tv.backgroundColor = [UIColor whiteColor]; 

    UITableViewCell *cell; 
    if (indexPath.row == 0) 
     cell = newsCell; 
    else if (indexPath.row == 1) 
     cell = configureCell; 
    else if (indexPath.row == 2) 
     cell = aboutCell; 

    return cell; 
} 

- (NSInteger)tableView:(UITableView *)tv numberOfRowsInSection:(NSInteger)section 
{ 
    return 0; 
} 

#pragma mark UITableViewDelegate Methods 


- (CGFloat)tableView:(UITableView *)tv 
heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 84; 
} 

- (void) tableView:(UITableView *)tv 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (0 == indexPath.row) 
    { 
    } 
    else if (1 == indexPath.row) 
    { 
    } 
    else if (2 == indexPath.row) 
    { 
    } 
} 


#pragma mark - 
#pragma mark Memory management 

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

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

- (void)viewDidUnload { 
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand. 
    // For example: self.myOutlet = nil; 
} 


- (void)dealloc { 
    [super dealloc]; 
    [tableView release]; 
    [newsCell release]; 
    [configureCell release]; 
    [aboutCell release]; 
} 

RootViewController.h

@interface RootViewController : UIViewController 
<UITableViewDataSource, UITableViewDelegate> 
{ 
    UITableView *tableView; 
    IBOutlet UIView *displaySplashScreen; 
    IBOutlet UITableViewCell *newsCell, *configureCell, *aboutCell; 
} 

@property (nonatomic, retain) IBOutlet UITableView *tableView; 
+0

+1 루트 익살에 대해 – PengOne

답변

3

여기에 몇 가지 문제가 있습니다. 먼저, AppDelegate에 헤더 읽어야합니다

@class RootViewController; 

@interface MyAppDelegate : NSObject <UIApplicationDelegate> { 
    UIWindow *window; 
    RootViewController *rootViewController; 
} 
@property (nonatomic, retain) IBOutlet UIWindow *window; 

@end 

그런 다음, 구현,이 같은 창에 네비게이션 컨트롤러에 루트를 추가하고 navController :

#import "RootViewController.h" 

@implementation MyAppDelegate 

@synthesize window; 

- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    rootViewController = [[RootViewController alloc] init]; 
    UINavigationController *navController = [[UINavigationController alloc] 
              initWithRootViewController:rootViewController]; 

    [window addSubview:[navController view]]; 
    [self.window makeKeyAndVisible]; 

    return YES; 
} 
+0

고마워요. 이렇게하면 내 코드가 정리되어 매우 감사하게 생각합니다. 그러나 내 장치에 표시된 검은 색 화면은 지우지 않으며 상태 표시 줄 만 맨 위에 표시됩니다. – Scott

+0

그러면 rootViewController에 대한 코드를 게시하는 것이 좋습니다. 특히 viewDidLoad 및 해당되는 경우 viewWillAppear. 문제가있을 수 있습니다. – PengOne

+0

수정 사항은 원래 게시물로 변경됩니다. 그들이 어떤 도움이 될지 의심 스럽다. – Scott

1

PengOne의 대답은 제외하고, 정확 나는 하나의 작은 변화를 만들 것이다. 수행 :

#import "RootViewController.h" 

@implementation MyAppDelegate 

@synthesize window; 

- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    rootViewcontroller = [[RootViewController alloc] init]; 
    UINavigationController *navController = [[UINavigationController alloc] 
             initWithRootViewController:rootViewController]; 

    self.window.rootViewController = navController; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

nav 컨트롤러를 표시하는 것이 더 좋습니다. PengOne도 말했듯이, Interface Builder 파일에 문제가 있습니다. 모든 것을 풀고 문제가 지속되는지 다시 확인하십시오. 그렇다면 모든 이름이 올바르게 지정되었는지 확인하십시오. 행운을 빕니다!

+0

좋아, 나는 성공없이 IB 파일 (RootViewController 및 MainWindow)을 재구성했다.IB가 어떻게 시뮬레이터가 아닌 장치에만 문제를 일으키는 지 알지 못합니다. 어쨌든, 나는 처음부터 전체 프로젝트를 재구성했고, 이제 모든 것은 시뮬레이터와 장치 모두에서 작동합니다. 배운 것은 없지만 효과가 있습니다. – Scott

+0

이상하게도 아주 희귀 한 것이 었음에 틀림 없습니다. 때로는 프로젝트를 "청소"(제품> 청소)하면 이런 펑키 문제를 해결하는 데 도움이됩니다. 미안해, 너 한테 그런 두통이 생겼어.하지만 지금은 다행이야. –

관련 문제