iOS AlertView 应用扩展 [英] iOS AlertView App Extension

查看:25
本文介绍了iOS AlertView 应用扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义 keyboard (iOS 应用扩展).我有一个 uicollectionview 在我的键盘 布局中,因此选择一个项目时,我想显示<代码>message(例如UIAlerView).

I'm working in a custom keyboard (iOS App Extension). I have a UICollectionView in my Keyboard Layout, so when one item is selected I want to show a message (UIAlerView for example).

这是我的代码:

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

 ...

UIAlertController * alert=   [UIAlertController
                              alertControllerWithTitle:@"My Title"
                              message:@"Enter User Credentials"
                              preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:alert animated:YES completion:nil];
}

我收到这个错误:'Feature not available in extensions of type com.apple.keyboard-service'

那么...有没有办法显示来自 App Extensionmessage ?

So...is there any way to show a message from an App Extension?

这是一个例子.IKEA Emoticons Keyboard 显示一条消息(就像选择一个项目后的 Android Toast).

Here is an example. The IKEA Emoticons Keyboard shows a message (like an Android Toast after selecting one item).

我也试过这个库:

iOS Toast 库

推荐答案

最后我解决了这个问题.这不是最好的解决方案,但至少我得到了我想要的效果.

Finally I solved the problem. It's not the best solution, but at least I get the effect that I wanted.

我在 xib 文件中创建了一个 View 模拟 Toast 并将其设置为 hidden.

I've created a View simulating a Toast in the xib file and set it to hidden.

当项目被选中时,我将伪造的"Toast 显示 2 秒钟,然后再次隐藏它.

When the item is selected, I show the "faked" Toast for 2 seconds and hide it again.

self.popUpView.hidden = NO;

dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2.0 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    self.popUpView.hidden = YES;
});

我不知道这是否是一个好的解决方案,但我真的必须为此找到一个解决方案.

I don't know if it's a good solution, but I really had to find a solution for that.

对于 Swift,你可以使用这个:

For Swift you can use this :

self.popUpView.isHidden = false
    DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
        self.popUpView.isHidden = true
    }

这篇关于iOS AlertView 应用扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆