iphone - Reusing detailed view controller in UISplitViewController -
basically when implement split view 1 presented in apple example 'multipledetailsviews', works fine, allocates new detailed view each time row selected. here relevant code example:
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { uiviewcontroller <substitutabledetailviewcontroller> *detailviewcontroller = nil; if (row == 0) { firstdetailviewcontroller *newdetailviewcontroller = [[firstdetailviewcontroller alloc] initwithnibname:@"firstdetailview" bundle:nil]; detailviewcontroller = newdetailviewcontroller; } // ... nsarray *viewcontrollers = [[nsarray alloc] initwithobjects:self.navigationcontroller, detailviewcontroller, nil]; splitviewcontroller.viewcontrollers = viewcontrollers; // ... }
but i'm looking reusing detailed view controllers, lazily allocating view controller when selected, , keeping reference on in object. way when row selected view controller not deallocated , when selected again reused instead of allocating new one. here relevant code:
- (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath { uiviewcontroller <substitutabledetailviewcontroller> *detailviewcontroller = nil; if (row == 0) { if (self.firstdetailviewcontroller == nil) { firstdetailviewcontroller *newdetailviewcontroller = [[firstdetailviewcontroller alloc] initwithnibname:@"firstdetailview" bundle:nil]; self.firstdetailviewcontroller = newdetailviewcontroller; [newdetailviewcontroller release]; } detailviewcontroller = self.firstdetailviewcontroller; } // ... nsarray *viewcontrollers = [[nsarray alloc] initwithobjects:self.navigationcontroller, detailviewcontroller, nil]; splitviewcontroller.viewcontrollers = viewcontrollers; // ... }
self.firstdetailviewcontroller
instanciated first time first row selected reused.
when i'm doing works in landscape mode in portrait mode after few clicks in popover menu raises exception: *** terminating app due uncaught exception 'nsinvalidargumentexception', reason: 'popovers cannot presented view not have window.'
so why care? , why don't want reallocate view controllers? because in of them want perform tasks wouldn't interrupted (killed) if user navigate in new detailed view while task isn't completed yet.
is there idea of happens or working implementation of i'm trying achieve?
this can achieved setting viewcontrollers property on new navigation controller previous detail controller:
- (void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender { if ([[segue identifier] isequaltostring:@"showdetail"]) { nsindexpath *indexpath = [self.tableview indexpathforselectedrow]; nsmanagedobject *object = [[self fetchedresultscontroller] objectatindexpath:indexpath]; uinavigationcontroller* navigationcontroller = (uinavigationcontroller*)[segue destinationviewcontroller]; // reuse existing controller navigationcontroller.viewcontrollers = @[self.detailviewcontroller]; // update detail controller normal. [controller setdetailitem:object]; controller.navigationitem.leftbarbuttonitem = self.splitviewcontroller.displaymodebuttonitem; controller.navigationitem.leftitemssupplementbackbutton = yes; } }
there overhead new detail controller unarchived , view loaded unfortunately.
Comments
Post a Comment