开发者

iOS Pass messages between views, window based app

So i'm working on an iPad window based app at the moment. There will be a number of views where I will want to pass some simple data between, mainly strings (id's) to tell the next view what to load.

Just wondering how to go about this开发者_如何学运维? I've come across this < http://idisk.mac.com/DChampney-Public/ViewControllerDataSharing.zip > solution which seems like the best but I am caught for time and it might be a little overkill for me at the moment.

Would it be ok to create a string in the appdelegate where I can store the id to be read by the next view?

Any ideas welcome..

Thanks.


  1. Define properties on your View Controllers for passing objects around (such as NSManagedObjectContext in all the Core Data samples & templates)
  2. Make one view controller the delegate of another, for passing data as the result of an event (such as selecting a tableview row, this is how UITableViewDelegate works)
  3. Use a publish/subscribe pattern for synchronous notifications between objects, through NSNotificationCenter. This should really only be used where more than one object might publish or subscribe, or where the connection between objects is distant (several view controllers between them). For async pub/sub use NSNotificationQueue

Do not use AppDelegate as the bag-of-data for your application. It's painful to change, bad design, and hard to read.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜