鍍金池/ 問(wèn)答/UI  HTML/ toast 在iOS上無(wú)法彈出的問(wèn)題

toast 在iOS上無(wú)法彈出的問(wèn)題

背景描述

發(fā)現(xiàn)toast不能正常顯示在iOS項(xiàng)目中。

vue的代碼如下

<template>
  <list>
    <cell @click="cellClicked(0)">
      <text>點(diǎn)我有彈框</text>
    </cell>
  </list>
</template>

<script>
  const { toast } = require('./util.js');
  const navigator = weex.requireModule('navigator');

  export default {
    methods: {
      cellClicked() {
        const modal = weex.requireModule('modal');
        modal.toast({
          message: '123120----3123',
          duration: 1,
        });
      }
    }
  }
</script>

編譯后的js在playground里面可以彈出toast,但在我的項(xiàng)目中卻不行。

我的環(huán)境

weexSDK: 0.18.0
$ weex -v
   v1.1.0-beta.7
 - weexpack : v0.4.7-beta.26
 - weex-builder : v0.2.13-beta.4
 - weex-devtool : v0.3.2-beta.11
 - weex-previewer : v1.3.13-beta.10

解決方法

查找資料,根據(jù)老倉(cāng)庫(kù)中的issue下提供的解決方案:

- (void)toast:(NSString *)message duration:(double)duration
{
    WXAssertMainThread();
    // UIView *superView = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
    // 將上行的代碼該為下行就好了。
    UIView *superView = [[[UIApplication sharedApplication] windows] lastObject];
    if (!superView) {
        superView = self.weexInstance.rootView;
    }
    UIView *toastView = [self toastViewForMessage:message superView:superView];
    WXToastInfo *info = [WXToastInfo new];
    info.toastView = toastView;
    info.superView = superView;
    info.duration = duration;
    [[WXToastManager sharedManager].toastQueue addObject:info];
    
    if (![WXToastManager sharedManager].toastingView) {
        [self showToast:toastView superView:superView duration:duration];
    }
}

經(jīng)過(guò)上面的修改后,發(fā)現(xiàn)toast就可以正常顯示了。

疑問(wèn)

我下載了0.18版本的playground,里面用的toast方法,獲取的superView就是UIView *superView = [[[UIApplication sharedApplication] windows] objectAtIndex:0];。 為什么同樣的代碼,在我的項(xiàng)目中就不能彈出,在playground就能彈出呢?

回答
編輯回答
尛憇藌

可以參考這條解決方案

2018年3月3日 01:08
編輯回答
孤影

我之前也是這樣改的

2017年1月23日 02:31