you can try `[UIApplication shareApplication].keyWindow` may be ok, if the toast view needs to be displayed, the superView must be the keyWindow, maybe this is a bug for toast module.
if it works, you can open an pull request to hep us fix it 2018-02-27 17:38 GMT+08:00 许有红 <emptywalk...@gmail.com>: > acton <zhangxing610...@gmail.com>于2018年2月27日 周二下午5:21写道: > > > I guess the reason is applications windows location, you can try to > debug > > by po all the windows both in your application and Weex Playground app > > > > the toast try to find a superview by getting the application windows. > > > > 2018-02-27 17:14 GMT+08:00 许有红 <emptywalk...@gmail.com>: > > > > > Toast cannot be displayed in your project, but can be displayed in the > > > playground. My environment is as follows: > > > > > > 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 > > > > > > The vue code is as follows: > > > > > > <template> > > > <list> > > > <cell @click="cellClicked(0)"> > > > <text>点我有弹框</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> > > > > > > > > > According to 'https://github.com/alibaba/weex/issues/2183', the > > following > > > solution is found: > > > > > > - (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]; > > > } > > > } > > > > > > > > > Q:Why doesn't the same code work in my project, but in the playground? > > > > > > > > > > > > > > I compared windows in two applications to get the following results. > > playground: > (lldb) po [[UIApplication sharedApplication] windows] > <__NSArrayM 0x600000057430>( > <UIWindow: 0x7fa239f00970; frame = (0 0; 414 736); gestureRecognizers = > <NSArray: 0x60c000049540>; layer = <UIWindowLayer: 0x60c000033640>>, > <WXWindow: 0x7fa239e06580; baseClass = UIWindow; frame = (110 0; 60 40); > gestureRecognizers = <NSArray: 0x60400025a940>; layer = <UIWindowLayer: > 0x604000222320>>, > <ATBaseWindow: 0x7fa239e03a30; baseClass = UIWindow; frame = (0 0; 414 > 736); gestureRecognizers = <NSArray: 0x60c000049780>; layer = > <UIWindowLayer: 0x60c0000338e0>> > ) > > my APP: > (lldb) po [[UIApplication sharedApplication] windows] > <__NSArrayM 0x608000252e10>( > <UIWindow: 0x7fe9dc106b50; frame = (0 0; 375 812); hidden = YES; > gestureRecognizers = <NSArray: 0x6080002510d0>; layer = <UIWindowLayer: > 0x60800003e2c0>>, > <UIWindow: 0x7fe9dc10db10; frame = (0 0; 375 812); gestureRecognizers = > <NSArray: 0x608000251970>; layer = <UIWindowLayer: 0x608000222020>> > ) > > > The first window in my project was hidden, so toast couldn't find > superView. > > In addition to modifying the SDK code, can you give us some Suggestions? > > > > >