iphone - why does this code use presentModalViewController? (not pushViewController) -
anyone understand why in coredatabooks example code that:
(a) method controller swapping difference
whilst click item , go detailed view uses seems standard uinavigationcontroller concept of "pushviewcontroller", when when click on "add" new record button launches new view add record via "presentmodalviewcontroller" approach? is, couldn't approach have been same in both cases, using pushviewcontroller approach?
are there advantages using each approach it's been used? can't quite see. i'd guess there must have been apple choose these different approaches different scenarios. example:
any differences user (i.e. ui differences or functional differences) see?
any differences developer (or advantages/disadvantages)
for example, if consider using pushviewcontroller approach instead of presentmodalviewcontroller approach for "add" scenario...
(b) data sharing approach difference
the approach how share common data object seems different - again wondering why approaches weren't same? (i.e. in both cases main controller passing off view temporarily , there shared data between them - i.e. child view needs pass parent)
code extract convenience
that "edit":
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { // create , push detail view controller. detailviewcontroller *detailviewcontroller = [[detailviewcontroller alloc] initwithstyle:uitableviewstylegrouped]; book *selectedbook = (book *)[[self fetchedresultscontroller] objectatindexpath:indexpath]; // pass selected book new view controller. detailviewcontroller.book = selectedbook; [self.navigationcontroller pushviewcontroller:detailviewcontroller animated:yes]; [detailviewcontroller release]; }
but "add"
- (ibaction)addbook { addviewcontroller *addviewcontroller = [[addviewcontroller alloc] initwithstyle:uitableviewstylegrouped]; addviewcontroller.delegate = self; // create new managed object context new book -- set persistent store coordinator same fetched results controller's context. nsmanagedobjectcontext *addingcontext = [[nsmanagedobjectcontext alloc] init]; self.addingmanagedobjectcontext = addingcontext; [addingcontext release]; [addingmanagedobjectcontext setpersistentstorecoordinator:[[fetchedresultscontroller managedobjectcontext] persistentstorecoordinator]]; addviewcontroller.book = (book *)[nsentitydescription insertnewobjectforentityforname:@"book" inmanagedobjectcontext:addingcontext]; uinavigationcontroller *navcontroller = [[uinavigationcontroller alloc] initwithrootviewcontroller:addviewcontroller]; [self.navigationcontroller presentmodalviewcontroller:navcontroller animated:yes]; [addviewcontroller release]; [navcontroller release]; }
thanks
you use modal view controllers focus user's attention on task. when push, user in kind of navigation flow, still has total application @ fingertips. might decide go forward or backward, switch different tab in middle, whatever. when modal view controller, can't of until task completed or canceled out of (the modal view dismissed)
Comments
Post a Comment