Instance Variables for Objective C Categories

前端 未结 8 1898
终归单人心
终归单人心 2020-12-02 15:43

I have a situation where it seems like I need to add instance variables to a category, but I know from Apple\'s docs that I can\'t do that. So I\'m wondering what the best a

8条回答
  •  春和景丽
    2020-12-02 16:03

    Depending on what you're doing, you may want to use Static Category Methods.

    So, I assume you've got this kind of problem:

    ScrollView has a couple of textedits in them. User types on text edit, you want to scroll the scroll view so the text edit is visible above the keyboard.

    + (void) staticScrollView: (ScrollView*)sv scrollsTo:(id)someView
    {
      // scroll view to someviews's position or some such.
    }
    

    returning from this wouldn't necessarily require the view to move back, and so it doesn't need to store anything.

    But that's all I can thinkof without code examples, sorry.

提交回复
热议问题