0

I have a custom UIActivity which return an UIViewController when the method - (UIViewController *)activityViewController has been called. But it end up showing a blank black screen instead of the UIViewController after clicking on the activity. Any idea what's wrong?

This is my code in the custom UIActivity:

- (void)prepareWithActivityItems:(NSArray *)activityItems
{

    self.vc = [[testaViewController alloc] init];
}

- (UIViewController *)activityViewController
{
    return self.vc;
}
daarkfish
  • 81
  • 9
  • Post with an example of a custom UIActivity: http://stackoverflow.com/questions/12766300/how-can-i-create-a-custom-uiactivity-in-ios-6-7 – pruinis Jan 29 '15 at 08:19
  • I'm assuming you designed your custom view in an XIB file? If so then you need to call `[[testaViewController alloc] initWithNibName:@"myNib" bundle:nil];` As it is you have a view controller with no view associated with it. – Rob Sanders Jan 29 '15 at 09:50
  • @pruinis the example return nil for method activityViewController – daarkfish Jan 29 '15 at 13:03
  • @RASS no ~ i'm using storyboard. – daarkfish Jan 29 '15 at 13:05
  • 1
    OK if the `activityViewController` method returns nil then you need to check you are retaining the view controller: i.e. that `self.vc` is a strong reference. Also even if you are using a storyboard the code: `[[testaViewController alloc] init];` will return a new view controller instance with no view property. Unless you have overriden the `init` method in the `testaViewController` class to load a view property. – Rob Sanders Jan 29 '15 at 14:34

1 Answers1

0

I changed my code to the following and it works now

- (void)prepareWithActivityItems:(NSArray *)activityItems
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main"    bundle:[NSBundle mainBundle]];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"testaviewcontroller"];
    self.vc = vc;
}

- (UIViewController *)activityViewController
{
    return self.vc;
}
daarkfish
  • 81
  • 9