Featured post
objective c - Class instances differ, which one to use? -
i'm stuck following. in program, i'm trying communicate between different classes (view controllers nib files attached in tabbar application etc). want call method 'omfg' in class called 'productviewdetailcontroller'. class uiviewcontroller (splitviewdelegate). it's loaded programmatically.
anyways, i've been trying right call controller, , came 2 solutions. 1 declaring productviewdetailcontroller in caller's .h file , .m file, making iboutlet, linking in interface builder , calling directly line
[productdetailcontroller omfg];
when call method, calls right method in productviewdetailcontroller, instance of viewcontroller differs 1 programmatically can reach code:
for (uiviewcontroller *controller in self.tabbarcontroller.viewcontrollers) { nslog(@"%@", [controller class]); if ([controller iskindofclass:[uisplitviewcontroller class]]) { uisplitviewcontroller *cell = (uisplitviewcontroller *)controller; (uiviewcontroller *controller2 in cell.viewcontrollers) { nslog(@"%@", [controller2 class]); if ([controller2 iskindofclass:[productviewdetailcontroller class]]) { [controller2 omfg]; } } }
which 1 should use, , why?
edit: when try add subview both viewcontrollers, 1 call [controller2 omfg]; shows newly added view, [productdetailcontroller omfg]; doesn't show newly added view... why that? there shorter (and more chique) way access right viewcontroller?
you should use iboutlet
. makes sure app can still call correct target if later decide change hierarchy of view controllers, example if creating iphone compatible setup without uisplitviewcontroller
.
calling iskindofclass:
in objective-c sure sign doing wrong. firstly in cocoa touch what do more important who are. secondly try peeking inside should left private.
- Get link
- X
- Other Apps
Comments
Post a Comment