-2

I have a framework that creates some views, the app that uses the framework calls a method from it and pass in the current view controller, the framework then calls presentModalViewController to display a view.

It was working just fine with iOS 6.1 SDK but when I updated to Xcode 5 and iOS 7 SDK I don't see the modal view anymore, instead all I get is a blank screen.

EDIT

Heres some code:

The Framework is called "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 is simply a view with a label that says "View from framework"

The framework itself works fine, calling sayHi method works just fine.

The third party app has a view with a label and a button which calls sayHi method and then displayView method, heres the view controller code:

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];
    }
}

The alert button action is also working correctly, I added a NSLog before and its working.

After clicking the alert button a view is presented but instead of containing the label "View from framework" I get a blank screen.

You can see the code on Github

EDIT 2

I got it... I wasn't calling initWithBundle on the ViewController from the framework, I added the a custom init method that calls:

framework: 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;
}

And changed testitiy.m

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

And now its working...

I hope this helps someone else but I'm guessing it was a stupid mistake of mine. Sorry for all the trouble and thanks for your time!

4

1 回答 1

1

所以过了一会儿,我终于明白了这个问题:

使用自定义框架时,图像和 NIB 文件等所有资源都必须手动包含在第三方应用程序中,以便它可以访问这些文件。

我的问题是我将资源(存储在包中)包含到第三方应用程序中,但框架试图根据自己的资源显示视图,应用程序无法访问,因此我得到了一个空白屏幕。

我只需要告诉框架在第三方应用程序中使用包含的包来显示该视图(使用 initWithNibName: Bundle 方法)。

请参阅问题中的 EDIT 2 以查看解决我的问题的代码。

希望这可以帮助某人。:-)

于 2013-10-11T15:19:40.860 回答