注意:在此之前,您应该检查 if 是否handleShortCutItem
被调用,并且 if-cases 是否按预期工作,并且self.quote_opt
不是 nil。
另一个注意事项:3D 通常在 中处理AppDelegate
,是这样处理的吗?
最后一点:您可能想看看:
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
由于 3D 动作是在应用程序打开后立即处理的,因此您的视图元素很可能尚未加载。因此,您需要保存 3D 动作中的信息并相应地加载。
您可以在负责的类中添加一个标志,然后在加载视图后进行相应的修改。
一个便于切换的枚举:
// You may add additional items to your enum.
typedef NS_ENUM(NSUInteger, ShortcutAction) {
ShortcutActionNone,
ShortcutActionA,
ShortcutActionB,
};
处理快捷方式:
- (void)handleShortCutItem:(UIApplicationShortcutItem *)shortcutItem
{
if([shortcutItem.type isEqualToString:@"3DQuickActionA"])
{
self.shortcutAction = ShortcutActionA;
}
else if([shortcutItem.type isEqualToString:@"3DQuickActionB"])
{
self.shortcutAction = ShortcutActionB;
}
// self.shortcutAction will be defaulted to 0 -> ShortcutActionNone.
}
处理段开关:
// You should put this in the interface of your class.
@property ShortcutAction shortcutAction;
// And the implementation:
- (void)viewDidLoad
{
[super viewDidLoad];
if(!self.quote_opt)
{
// You have other problems, the quote_opt is not initialized yet, or properly.
NSLog(@"ERR");
}
switch(self.shortcutAction)
{
case ShortcutActionNone:
{
// no-op
break;
}
case ShortcutActionA:
{
self.quote_opt.selectedSegmentIndex = 0;
break;
}
case ShortcutActionB:
{
self.quote_opt.selectedSegmentIndex = 1;
break;
}
}
}