ios - Call Different Method Depending On The View Controller Selected -
its complicated put in words lemme give try. have menuviewcontroller has array category names, tapping on category rows in tableview instantiate different view controller using storyboard id.
now if use different classes each view controller, lot of redundant code , classes. want use 1 class these view controllers lets call primaryviewcontroller , upon selecting different categories in menuviewcontroller, calls different methods or blocks in primaryviewcontroller.
here method in primaryviewcontroller:
- (void) fetchdata:(nsinteger )pagenumber { channel = [[thefeedstore sharedstore] fetchwebservice:pagenumber withcompletion:^(rsschannel *obj, nserror *err){ if (!err) { int currentitemcount = [[channel items] count]; channel = obj; int newitemcount = [[channel items] count]; int itemdelta = newitemcount - currentitemcount; if (itemdelta > 0) { nsmutablearray *rows = [nsmutablearray array]; (int = 0; < itemdelta; i++) { nsindexpath *ip = [nsindexpath indexpathforrow:i insection:0]; [rows addobject:ip]; } [[self tableview] insertrowsatindexpaths:rows withrowanimation:uitableviewrowanimationbottom]; } } }]; }
the above code has ability load 1 category. notice first line "channel = [[thefeedstore sharedstore] fetchwebservice", other categories named "fetchwebservicecat2", "fetchwebservicecat3" , "fetchwebservicecat4" in class named thefeedstore.
what want when different view controller instantiated menuviewcontroller, should use primaryviewcontroller's fetchdata method call different category method of thefeedstore.
thanks!
[store fetchwebservice:webservice withcompletion:completion];
is equivalent to:
[store performselector:@selector(fetchwebservice:withcompletion:) withobject:webservice withobject:completion];
so can this:
sel sel = nil; if (...) sel = @selector(fetchwebservice:withcompletion:); if (...) sel = @selector(fetchwebservicecat2:withcompletion:); ... [store performselector:sel withobject:webservice withobject:^{}];
or this:
sel sel = nsselectorfromstring([nsstring stringwithformat:@"fetchwebservice%@:withcompletion:", @"cat2"]); ...
Comments
Post a Comment