2013-10-01 52 views
-2

我有一個框架創建了一些視圖,使用該框架的應用程序從它調用一個方法並傳入當前的視圖控制器,框架然後調用presentModalViewController來顯示一個視圖。ios7來自框架的空白屏幕

它與iOS 6.1 SDK一起工作得很好,但是當我更新到Xcode 5和iOS 7 SDK時,我再也看不到模態視圖,而我只能看到一個空白屏幕。

編輯

繼承人一些代碼:

框架被稱爲 「testityi」

testityi.m

#import "TestViewController.h" 

@implementation testitiy 

- (NSString*) sayHi : (NSString*) name { 
    return [NSString stringWithFormat:@"Hello %@", name]; 
} 

- (void) displayView:(UIViewController *)parentController { 
    TestViewController* controller = [[TestViewController alloc] init]; 
    [parentController presentViewController:controller animated:YES completion:nil]; 
} 

TestViewController僅僅是一個標籤,上面寫着一個視圖「從框架中查看」

框架本身工作正常,調用sayHi方法工作得很好。

的第三方應用程序具有一個標籤和它調用sayHi的方法,然後displayView方法按鈕,繼承人視圖控制器代碼的圖:

MainViewController.m

- (IBAction)buttonPressed:(id)sender { 
    testitiy* framework = [[testitiy alloc] init]; 
    NSString* msg = [NSString stringWithFormat:@"Calling sayHi method on framework...\n  result: %@", [framework sayHi:@"John"]]; 
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"sayHi method call"  message:msg delegate:self cancelButtonTitle:@"Ok, show me the view" otherButtonTitles:nil, nil]; 
    [alert show]; 
} 

-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if(buttonIndex == [alertView cancelButtonIndex]) { 
     testitiy* framework = [[testitiy alloc] init]; 
     [framework displayView:self]; 
    } 
} 

警報按鈕操作也正常工作,我添加了一個NSLog之前,它的工作。

單擊警報按鈕後,將顯示一個視圖,但不包含標籤「從框架查看」,我得到一個空白屏幕。

你可以看到Github

EDIT 2

我得到了它的代碼...我是不是從框架調用initWithBundle上的ViewController,我添加了一個自定義的init方法調用:

框架:TestViewController.m

+ (NSBundle *)frameworkBundle { 
    static NSBundle* frameworkBundle = nil; 
    static dispatch_once_t predicate; 
    dispatch_once(&predicate, ^{ 
     NSString* mainBundlePath = [[NSBundle mainBundle] resourcePath]; 
     NSString* frameworkBundlePath = [mainBundlePath  stringByAppendingPathComponent:@"testity.bundle"]; 
     frameworkBundle = [NSBundle bundleWithPath:frameworkBundlePath]; 
    }); 
    return frameworkBundle; 
} 

- (id) initWithFramework { 
    NSBundle* bundle = [[self class] frameworkBundle]; 
    self = [super initWithNibName:@"TestViewController" bundle: bundle]; 
    return self; 
} 

,改變了testitiy.m

- (void) displayView:(UIViewController *)parentController { 
    TestViewController* controller = [[TestViewController alloc] initWithFramework]; 
    [parentController presentViewController:controller animated:YES completion:nil]; 
    //[parentController.navigationController pushViewController:controller animated:YES]; 
} 

而現在它的工作...

我希望這可以幫助別人,但我猜這是我的一個愚蠢的錯誤。 對不起所有的麻煩和感謝您的時間!

+0

沒有一些代碼很難說。 –

+0

'presentModalViewController:'已棄用。看看是否調用適當的'presentViewController:animated:completion:'工作。 – Kevin

+1

A衝進一次會議,並說:「哦,啊,啊,抱歉...但是有些東西似乎停止了工作......」B回答:「你應該找人來修理它!」 – Till

回答

1

所以一段時間後,我終於明白了一個問題:

在使用自定義的框架,如圖像和NIB文件中的所有資源必須手動包含在第三方應用程序,以便它可以訪問這些文件。

我的問題是,我將資源(存儲在一個包中)包含到第三方應用程序中,但框架試圖根據自己的資源顯示該應用程序無法訪問的資源,我得到一個空白屏幕的原因。

我只是需要告訴框架使用包含的包到第三方應用程序來顯示該視圖(使用initWithNibName:Bundle方法)。

請參閱編輯2在問題中看到解決我的問題的代碼。

希望這可以幫助別人。 :-)

+0

如何在捆綁中創建xibs和圖像?任何參考? –

+0

行得通......謝謝你 –