当我使用UIImagePicker访问我的照片库来选择照片时,该应用程序有时会向我显示黑屏,有时会显示一个屏幕,说我必须授予我的应用访问照片的权限.但是,当我进入设置 - >隐私 - >照片时,那里没有应用程序,应用程序无法在"设置"中看到.我读到我必须在我的Info.plist中添加两个值,但它们也没有用.有没有人运行相同的错误?我正在使用xcode 7,swift 2.0和iOS 9
这是我提示用户进行相机访问的地方
@IBAction func cameraButtonPressed(sender: UIButton) {
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
let cancelAction = UIAlertAction(title: "Cancel", style: .Default) { (UIAlertAction) -> Void in
self.dismissViewControllerAnimated(true, completion: nil)
}
let cameraAction = UIAlertAction(title: "Take Photo", style: .Default) { (UIAlertAction) -> Void in
if UIImagePickerController.availableCaptureModesForCameraDevice(.Rear) != nil {
self.imagePicker.allowsEditing = false
self.imagePicker.sourceType = UIImagePickerControllerSourceType.Camera
self.imagePicker.cameraCaptureMode = .Photo
self.presentViewController(self.imagePicker, animated: true, completion: nil)
} else {
self.noCamera()
}
}
let photoLibraryAction = …Run Code Online (Sandbox Code Playgroud) 我有一个 FragmentStateAdapter 作为 ViewPager2 的适配器。
class DefaultFragmentStateAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
var items = listOf<Fragment>()
set(value) {
field = value
notifyDateSetChanged()
}
override fun getItemCount(): Int = items.size
override fun createFragment(position: Int): Fragment = items[position]
}
Run Code Online (Sandbox Code Playgroud)
适配器项可以根据用户选择的日期进行更改,因此它需要是动态的。发生的情况是,在我调用adapter.items = {new_fragments}当前片段后没有重新加载,只有在我转到 ViewPager 中的最后一页并返回第一页后,我才能看到更新的片段。当前片段在notifyDataSetChanged被调用时不会更新。
我怎样才能更新当前显示的片段?