Can you access application delegate from within a UITableViewDataSource function?

后端 未结 4 1981
余生分开走
余生分开走 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:15

    The Application is a singleton which maintains a reference to the app delegate. You can always access your app delegate using:

    [UIApplication sharedApplication].delegate
    

    You may need to cast the return to your own app delegate class to get rid of warnings. Even better, write an accessor that returns your upcast app delegate:

    #pragma mark access to app delegate etc.
    + (MyAppDelegateClass*) sharedAppDelegate; {
        return (MyAppDelegateClass*)[[UIApplication sharedApplication] delegate];
    }
    

提交回复
热议问题