【问题标题】:Can't assign custom class to Page View Controller无法将自定义类分配给页面视图控制器
【发布时间】:2014-07-13 17:40:19
【问题描述】:

我正在使用情节提要并添加了一个页面视图控制器,现在我想对其进行配置以使用我自己的自定义类。为此,我选择了在 Identity Inspector 下的 Custom Class 中指示使用 UIPageViewController 的页面视图控制器。我设置了我自己的 WinkPageViewController,但我得到了“碰撞”的声音,并且再次取消选择 + 选择视图控制器显示该属性已重置为之前的值。

我不确定代码的哪些部分是相关的,所以我暂时将界面留在这里,但如果还有其他相关内容,请告诉我。

@interface WinkPageViewController : UIViewController <UIPageViewControllerDelegate>

@property (nonatomic, strong) UIPageViewController* pageViewController;
@property (nonatomic, strong) WinkPageModelController* modelController;

//// Sent when a gesture-initiated transition begins.
//- (void)pageViewController:(UIPageViewController *)pageViewController willTransitionToViewControllers:(NSArray *)pendingViewControllers NS_AVAILABLE_IOS(6_0);
//
//// Sent when a gesture-initiated transition ends. The 'finished' parameter indicates whether the animation finished, while the 'completed' parameter indicates whether the transition completed or bailed out (if the user let go early).
//- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed;
//
//// Delegate may specify a different spine location for after the interface orientation change. Only sent for transition style 'UIPageViewControllerTransitionStylePageCurl'.
//// Delegate may set new view controllers or update double-sided state within this method's implementation as well.
//- (UIPageViewControllerSpineLocation)pageViewController:(UIPageViewController *)pageViewController spineLocationForInterfaceOrientation:(UIInterfaceOrientation)orientation;
//
//- (NSUInteger)pageViewControllerSupportedInterfaceOrientations:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(7_0);
//- (UIInterfaceOrientation)pageViewControllerPreferredInterfaceOrientationForPresentation:(UIPageViewController *)pageViewController NS_AVAILABLE_IOS(7_0);

- (WinkOAuthProfileProviderIdentifier)profileProviderPreference;
- (void)saveProfileProviderPreference:(WinkOAuthProfileProviderIdentifier)preference;
- (NSURL*)profileURLWithProviderIdentifier:(WinkOAuthProfileProviderIdentifier)provider error:(NSError**)error;
- (void)saveProfile:(WinkProfile*)profile error:(NSError**)error;
- (WinkProfileData*)loadProfileWithProviderIdentifier:(WinkOAuthProfileProviderIdentifier)provider error:(NSError**)error;

- (void)didReceiveProfile:(WinkProfile*)profile;

@end

我知道我没有实现 UIPageViewControllerDelegate 可选方法(恰好是所有这些方法),但我之前已经在 swift 中完成了这个并且它有效。我该怎么办?

【问题讨论】:

  • 我假设你已经在其他地方实现了UIPageViewControllerDataSource,对吧?
  • 是的。 WinkPageModelController 实现了该协议。这就是我发布的代码中的modelController 属性
  • 顺便说一句,我的场景中还有两个视图控制器(不是页面视图控制器),它们都有自定义类。这么多。

标签: ios objective-c xcode storyboard


【解决方案1】:

正方形是长方形,但长方形不一定是正方形

页面视图控制器(来自故事板中的对象库)代表UIPageViewController

视图控制器(来自 Storyboard 中的对象库)表示 UIViewController

WinkPageViewController 继承自 UIViewController,不能代表 Page View Controller 对象的自定义类。


UIPageViewController 类参考

https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIPageViewControllerClassReferenceClassRef/UIPageViewControllerClassReference.html

【讨论】:

  • 如此简单。我不会猜到一个原因:如果我在那里写了 anything else,它就会编译。我的意思是随机文本。所以它允许不存在的标识符,但不允许不符合某些标准的标识符。很高兴知道。谢谢。
猜你喜欢
  • 2016-02-10
  • 1970-01-01
  • 2019-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多