Can you access application delegate from within a UITableViewDataSource function?

后端 未结 4 1983
余生分开走
余生分开走 2021-01-01 09:42

I\'m trying to figure out the SQLite functionality for the iPhone, and I\'m having some problems reading my database file from an overridden UITableViewDataSource function.

4条回答
  •  我在风中等你
    2021-01-01 10:26

    While I don't like sticking too much into my AppDelegate, I'll often need to access it to get to other singletons in my app, which makes the method call + cast a little cumbersome. So in most of my apps, I'll define a quick macro in my global header file.

    Example follows:

    
    #define MY_DELEGATE (AppDelegate*)[[UIApplication sharedApplication] delegate]
    

    It's a lot easier to refer to MY_DELEGATE.

提交回复
热议问题