1and2papa / CTAssetsPickerController

iOS control that allows picking multiple photos and videos from user's photo library.
MIT License
2.15k stars 550 forks source link

show blank page after presented in form sheet style on Swift iPad App #177

Closed wjiuxing closed 8 years ago

wjiuxing commented 8 years ago

I have a Swift project. I want to present this picker in form sheet on iPad. But it shows me a blank view, see screenshot at the end pls.

Steps to reproduce: 0- I'm using Xcode 7.1.1 1- new a Master-Detail Application in Swift 2- add CTAssetsPickerController to Podfile and run pod install 3- change the MasterViewController

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        PHPhotoLibrary.requestAuthorization({ (status) -> Void in
            dispatch_async(dispatch_get_main_queue(), { () -> Void in
                // init picker
                self.assetsPicker = CTAssetsPickerController()

                // set delegate
                self.assetsPicker.delegate = self

                // set default album (Camera Roll)
                self.assetsPicker.defaultAssetCollection = .SmartAlbumUserLibrary

                if UIDevice.currentDevice().userInterfaceIdiom == .Pad {
                    self.assetsPicker.modalPresentationStyle = .FormSheet
                }

                // present picker
                self.presentViewController(self.assetsPicker, animated: true, completion: nil)
            })
        })
   }

4- run the app and add an entry by clicking on the "+" on the right bar button of MasterViewController 5- click on the new cell inserted above. At this time above code will be called. 6- show a blank page as the image following.

ctassetspickercontroller shown as a blank page in form sheet style

Thank you very much. :)

wjiuxing commented 8 years ago

I did above steps with an Objective-C project. And I found the code works well in Objective-C. But I haven't done anything else but translate the code from Swift to Objective-C. I think there may be bugs in Swift.

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

   [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
       dispatch_async(dispatch_get_main_queue(), ^{

         // init picker
         CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init];

         // set delegate
         picker.delegate = self;

         // set default album (Camera Roll)
         self.assetsPicker.defaultAssetCollection = PHAssetCollectionSubtypeSmartAlbumUserLibrary;

         // to present picker as a form sheet in iPad
         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
              picker.modalPresentationStyle = UIModalPresentationFormSheet;
         }

         // present picker
         [self presentViewController:picker animated:YES completion:nil];
       });
    }];
}
1and2papa commented 8 years ago

@wjiuxing Noted and thanks.

JasonPan commented 8 years ago

Hi, I just wanted to share: I've been experiencing the same issue. I tried not using the defaultAssetCollection property, and that fixed it. Any ideas why?

Thanks

armandzwan commented 8 years ago

I'm getting the same blank screen, but in an Objective-C project. Trying to get my head around it. Did you fix this?

1and2papa commented 8 years ago

Please refer to #160.