Refactoring 3 different UI components into one UIView into a CocoaPod

笑着哭i 提交于 2019-12-11 10:47:31

问题


in my iOS project i've been re-using the same 3 different types of UI elements:

  • Label
  • input
  • check mark (or X ).

And the logic is the same:

  • when the user is entering text, validate.
  • while validation fails, red check mark,etc.

So, the next obvious stage is to refactor this into one UIView so that I can just drag and drop.

And I want this into a Cocoa pod.

Refactoring the elements into a UIview, etc is not hard. But I'm stuck on putting this logic into a Cocoa Pod. The XIB doesn't load so the subview is empty.

I've added IB_DESIGNABLE to the header file but still no rendering. And exception at runtime.

Suggestions? What can I post to help?

EDIT:

My resource section of the podspec

s.source_files = 'Pod/Classes/**/*'
  s.resources = 'Pod/Assets/**/*'
  s.resource_bundles = {
    'jawbreaker' => ['Pod/Assets/*.png']
  }

回答1:


UIView doesnt load XIB file automatically. When you create an UIView class you need something like this: http://eppz.eu/blog/uiview-from-xib-simplest/ .

MyView *view = [Myview loadFromNib];

An if you want use IB_DESIGNABLE remember: https://stackoverflow.com/a/26202160/846780




回答2:


You might be missing the s.resource_bundle directive, where you specify which NIBs to load.



来源:https://stackoverflow.com/questions/29082170/refactoring-3-different-ui-components-into-one-uiview-into-a-cocoapod

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!