2017年1月12日
一动态类创建和动态选择方法
1.动态选择创建不同的类
- (void)dealPushMessage:(HuMessagePushType)pushType
{
if (![HuConfigration loginStatus]) {
loginViewController * loginVC = [[loginViewController alloc] init];
[[[UIApplication sharedApplication] delegate] window].rootViewController = loginVC;
}
else
{
switch (pushType) {
case HuMessagePushTypeHospitalMessage:
{
[kNotificationCenter postNotificationName:kNotificationRed object:nil];
[self gotoViewControllerStr:@"MyHospitalMessageViewController" WithMenuBar:HuMainPageMenuBarTypePersonalCenter];
}
break;
case HuMessagePushTypeSystemMessage:
{
[kNotificationCenter postNotificationName:kNotificationRed object:nil];
[self gotoViewControllerStr:@"SystemMessagesViewController" WithMenuBar:HuMainPageMenuBarTypePersonalCenter];
}
break;
default:
break;
}
}
}
- (void)gotoViewControllerStr:(NSString*)vcStr WithMenuBar:(HuMainPageMenuBarType)type
{
[self goToMainPage:type];
NSInteger i = type - 1;
UINavigationController *nav = [[_customVc childViewControllers] objectAtIndex:i];
UIViewController *vc = [[NSClassFromString(vcStr) alloc] init];
[nav pushViewController:vc animated:YES];
[_customVc hiddenTabBar];
}
2.动态选择方法
- (SEL)findMethodForPacket: (id)packet
{
if ([packet respondsToSelector:@selector(insertValue:ColumnName:)]) {//HsTablePacket
return @selector(insertValue:ColumnName:);
}
else if ([packet respondsToSelector:@selector(setValue:forColumn:)]) {//HsTradeQueryPacket
return @selector(setValue:forColumn:);
}
HuLogDebug(@"[Warning] findMethodForPacket");
return nil;
}
//setInputContent 没有提交
- (void)setLoginInfoToPacket: (id)packet
{
SEL theSelector = [self findMethodForPacket:packet];
[packet performSelector:theSelector withObject:[[HsTradeConfigration sharedManager] entrustWayForTradeType] withObject:@"entrust_way"];
[packet performSelector:theSelector withObject:[[HsTradeConfigration sharedManager] entrustWayForTradeType] withObject:@"op_entrust_way"];
}
如果您发现本文对你有所帮助,如果您认为其他人也可能受益,请把它分享出去。