美文网首页
App2.0 问题汇总记录

App2.0 问题汇总记录

作者: Vampire丶Lv | 来源:发表于2018-06-05 23:09 被阅读21次

    1、webview使用过程中报错,错误场景是使用通知从webview所在的控制器进行操作以回退页面,但是崩溃报错,如下:

    void SendDelegateMessage(NSInvocation *): delegate (webView:decidePolicyForNavigationAction:request:frame:decisionListener:) failed to return after waiting 10 seconds. main run loop mode: kCFRunLoopDefaultMode
    解决方案如下:
    -(void)dealloc{
    if(_mainWebView){
    [_mainWebView stopLoading];
    _mainWebView.delegate = nil;
    }
    }

    2、使用场景:导航栏一级页面A——>B(web页面)——>C(导航栏一级页面),账户页面发起充值,充值完成跳到项目出借列表,出现问题:从web控制器跳到C之后,底部的tabbar消失了:

    跳转的时候使用VC.hidesBottomBarWhenPushed = YES;然后在跳转的时候使用了通知,让A页面跳C self.selectedIndex = 1;用通知发现退出B的时候没有走viewWillDisappear,没法执行方法。

    解决方案:不使用通知,方法写在viewWillDisappear里面, 图片.png

    3、ApplicationLoader登录失败. Please sign in with an app-specific password. 图片.png

    打包时登录ApplicationLoader时 报错:Please sign in with an app-specific password. You can create one at appleid.apple.com
    出现这个错误的原因是 账号开启了双重认证;解决方法如下:

    1、在Apple官网登陆你的账号,点击右上角账号管理(Account Settings) -> Manage my Apple ID 示例

    4、OC调用JS,交互问题

    方式一:NSString *jsStr = [NSString stringWithFormat:@"showAlert('%@')",@"这里是JS中alert弹出的message"];
    [_webView stringByEvaluatingJavaScriptFromString:jsStr];
    方式二: (推荐这种)使用JavaScriptCore库来做JS交互。
    JSContext *context = [self.webView valueForKeyPath:@"documentView.webView.mainFrame.javaScriptContext"];
    NSString *textJS = @"showAlert('这里是JS中alert弹出的message')";
    [context evaluateScript:textJS];

    使用过程中,正常调用但是js方法不执行,可能原因是执行调用js方法需要放在webview加载完成的代理方法里面: js交互

    5、管理视图层次 Managing the View Hierarchy

    • (void)addSubview:(UIView *)view //添加子视图
    • (void)removeFromSuperview //从父视图中移除
    • (void)bringSubviewToFront:(UIView *)view //移动指定的子视图到最顶层
    • (void)sendSubviewToBack:(UIView *)view //移动制定的子视图到后方,所有子视图的下面
    • (void)insertSubview:(UIView *)view atIndex:(NSInteger)index
      //在指定的位置插入子视图,视图的所有视图其实组成了一个数组
    • (void)insertSubview:(UIView *)view aboveSubview:(UIView *)siblingSubview
      //将指定的子视图移动到指定siblingSubview子视图的前面
    • (void)insertSubview:(UIView *)view belowSubview:(UIView *)siblingSubview
      //将指定的子视图移动到指定siblingSubview子视图的后面
    • (void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2 //交换两子视图的位置
    • (BOOL)isDescendantOfView:(UIView *)view
      //判断接收对象是否是指定视图的子视图,或与指定视图是同一视图
    • (void)layoutSubviews //勾画子视图
    • (void)layoutIfNeeded //立即勾画子视图
    • (void)setNeedsLayout //使当前接收对象的布局作废,并在下一更新周期触发一个新的布局

    6、TabBar底部有消息时显示小红点:

    创建UITabbar类别,
    .h代码

    import <UIKit/UIKit.h>

    @interface UITabBar (Tabbar_Hongdian)

    • (void)showBadgeOnItemIndex:(NSInteger)index; ///<显示小红点
    • (void)hideBadgeOnItemIndex:(NSInteger)index; ///<隐藏小红点
      @end

    .m代码:

    import "UITabBar+Tabbar_Hongdian.h"

    define TabbarItemNums 4.0 //tabbar的数量 如果是5个设置为5

    @implementation UITabBar (Tabbar_Hongdian)

    //显示小红点

    • (void)showBadgeOnItemIndex:(NSInteger)index{
      //移除之前的小红点
      [self removeBadgeOnItemIndex:index];

      //新建小红点
      UIView *badgeView = [[UIView alloc]init];
      badgeView.tag = 888 + index;
      badgeView.layer.cornerRadius = 5.0;//圆形
      badgeView.backgroundColor = [UIColor redColor];//颜色:红色
      CGRect tabFrame = self.frame;

      //确定小红点的位置
      CGFloat percentX = (index + 0.6) / TabbarItemNums;
      CGFloat x = ceilf(percentX * tabFrame.size.width);
      CGFloat y = ceilf(0.1 * tabFrame.size.height);
      badgeView.frame = CGRectMake(x, y, 10.0, 10.0);//圆形大小为10
      badgeView.clipsToBounds = YES;
      [self addSubview:badgeView];
      }

    //隐藏小红点

    • (void)hideBadgeOnItemIndex:(NSInteger)index{
      //移除小红点
      [self removeBadgeOnItemIndex:index];
      }

    //移除小红点

    • (void)removeBadgeOnItemIndex:(NSInteger)index{
      //按照tag值进行移除
      for (UIView *subView in self.subviews) {
      if (subView.tag == 888+index) {
      [subView removeFromSuperview];
      }
      }
      }
      @end

    关于调用:
    直接在tabbar的VC里面调用就可以


    示例

    相关文章

      网友评论

          本文标题:App2.0 问题汇总记录

          本文链接:https://www.haomeiwen.com/subject/jmrcsftx.html