zoukankan      html  css  js  c++  java
  • ios 问题集

    1.用UIWebView 加载一个不存在的网址(https://developer.apple),我在加载失败的事件中,调用 [self.browser stopLoading] 但是,iphone系统上标示网络的小菊花还老在转?

     

    2.用选项卡,导航栏做一个主要框架,如何只让其中的某些view(对应的controller的title为 selfbrowser browser)支持旋转?

     1 //#pragma mark - Rotation UITabBarController category
     2 
     3 @implementation UITabBarController (Rotate)
     4 -(BOOL)shouldAutorotate
     5 {
     6     UINavigationController *vc = (UINavigationController *)self.selectedViewController;
     7     
     8     if ([vc isEqual: [self.viewControllers objectAtIndex:0]])
     9     {
    10         return YES;
    11     }
    12     return NO;
    13 }
    14 
    15 -(NSUInteger)supportedInterfaceOrientations
    16 {
    17     UINavigationController *vc = (UINavigationController *)self.selectedViewController;
    18     
    19     if ([vc isEqual: [self.viewControllers objectAtIndex:0]])
    20     {
    21         UIViewController* viewctrl = vc.visibleViewController;
    22         if ([viewctrl.title isEqual:@"selfbrowser"]
    23             || [viewctrl.title isEqual:@"browser"])
    24         {
    25             return UIInterfaceOrientationMaskAllButUpsideDown;
    26         }
    27     }
    28     
    29     return UIInterfaceOrientationMaskPortrait;
    30 }
    31 
    32 @end
    View Code

    3.第2个问题解决了,发现另一个问题,某一个支持旋转viewA,她的上一个viewB不支持旋转,当viewA旋转后,用导航栏返回时,发现viewB也被旋转了,不知道如何手工把viewB旋转回来?

    4.如何在app中与嵌入到UIWebView中的web进行一定的交互呢?

     1 //让web触发某个连接,app可以得到响应
     2 - (BOOL)webView: (UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
     3 {
     4     //获取到对应的连接,做逻辑处理
     5     NSString *requestString = [[[request URL] absoluteString] stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
     6     
     7     if ([requestString isEqualToString:@"http://qweq.weibo.com/12345678yqlzq"]
     8         || [requestString isEqualToString:@"http://192.168.1.50:1834/mobile2/about.html#/mobile2/coupons.html"])
     9     {
    10         [self.navigationController popViewControllerAnimated:YES];
    11         return NO;
    12     }
    13     return YES;
    14 }
    View Code

     5.如何手工创建UIButton?

     1     UIButton* btnTry = [UIButton buttonWithType:UIButtonTypeRoundedRect];
     2     [btnTry setFrame:CGRectMake(self.view.frame.size.width/2-45, self.view.frame.size.height/2, 90, 40)];
     3     [btnTry setBackgroundImage:[[UIImage imageNamed:@"Icon.png"]stretchableImageWithLeftCapWidth:0.0 topCapHeight:0.0] forState:UIControlStateNormal];
     4     [btnTry.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
     5     [btnTry setTitle:@"重试" forState:UIControlStateNormal];
     6     [btnTry setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
     7     btnTry.backgroundColor = [UIColor clearColor];
     8     [btnTry setHidden:YES];
     9     [btnTry setTag:55];
    10     [btnTry addTarget:self action:@selector(onBtnTry:) forControlEvents:UIControlEventTouchUpInside];
    11     [view addSubview:btnTry];
    View Code

     6.开发者 A 开发一个app项目,现在我需要接手他的项目,(设备iphone,开发者都不一样)那么如何来调试呢?

        进入apple developer网站重新生成一个描述文件,选择同样一个app id, 选择自己的开发帐号,选择自己的调试设备iPhone5,生成一个新的描述文件。安装到自己的XCode以及调试设备iphone5上就可以调试了。

    7.对工程A,拷贝了一份工程B,然后对B进行编辑,过一段时间后,需要重新在A的基础上做其它修改,于是对A进行拷贝为C,运行C,发现有些行为类似A,有些类似B,设置断点,有的可以进入到断点,有的不可以,乱套了?

      打开C工程=>Product =>Clean,然后关闭C工程,右键Xcode,退出,然后重启XCode,重新运行C工程,就OK了。

    8.UIActionSheet最后一个按钮没响应,一般是cancelButton,要稍微向上偏移一点才可以。

    这是在特定情况下才会发生,这个场景就是试用了UITabBar的时候才有。

    参考:http://stackoverflow.com/questions/2096852/iphone-weird-bug-between-uiactionsheet-and-uitabbar

    解决办法:

     1 UIActionSheet *action  =
     2 
     3         [[UIActionSheet alloc] initWithTitle:@"您是否拨打"
     4 
     5                                     delegate:self 
     6 
     7                            cancelButtonTitle:@"取消拨打"
     8 
     9                       destructiveButtonTitle:@"拨打" 
    10 
    11                            otherButtonTitles:@"加入电话本",nil];
    12 
    13         //[action showInView:self.view];  把这行更换为下面这个
    14 
    15         [action showInView:[UIApplication sharedApplication].keyWindow];
    16 
    17         [action release]; 
    View Code

     

    据闻是tabbar刚好在取消按钮的地方,所以离奇了,不过UIActionSheet是在tabbar上方,很难想象会出现这个问题。

     9.bug -- Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [0 nan; 320 nan]' 

     开始以为不是必现的,后来才知道原来是,用到了一个image,而这个image为nil,代码中去获取这个image的大小来计算其它控件的大小,导致了出现上述问题。

    10.如何升级已经上线的app

    登录iTunes Connect网站 -->查看该app信息-->add new version-->Prepare for Upload-->Waiting For Upload-->生成Achive然后提交即可

    11.如何设置程序图标及启动画面

    把相应的 Default.png Default@2x.png Icon.png Icon@2x.png 拷贝到工程,并通过 targets-->summary-->App Icons /launch images 设置即可。

     12.如何隐藏 导航栏

    [self.navigationController setNavigationBarHidden:YES animated:NO];

    13.如何把一个view放到最顶层

    [self.view bringSubviewToFront:mBtnHome];

    14.如何设置一个UIView的背景图片

     

        UIImageView *bgImgView = [[UIImageView alloc] initWithFrame:self.view.bounds];
        [bgImgView setImage:[UIImage imageNamed:@"bg.png"]];
        [self.view addSubview:bgImgView];
        [self.view sendSubviewToBack:bgImgView];

     15.如何指定图片的拉伸区域

    - (UIImage *)resizableImageWithCapInsets:(UIEdgeInsets)capInsets resizingMode:(UIImageResizingMode)resizingMode

    UIEdgeInsets类型的参数,

    可以通过设置UIEdgeInsets的left、right、top、bottom来分别指定左端盖宽度、右端盖宽度、顶端盖高度、底端盖高度

    UIImageResizingMode参数,用来指定拉伸的模式:

    • UIImageResizingModeStretch:拉伸模式,通过拉伸UIEdgeInsets指定的矩形区域来填充图片
    • UIImageResizingModeTile:平铺模式,通过重复显示UIEdgeInsets指定的矩形区域来填充图片
    CGFloat top = 25;      //顶端盖高度
    CGFloat bottom = 25 ;   //底端盖高度
    CGFloat left = 10;     //左端盖宽度
    CGFloat right = 10;     //右端盖宽度
    UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
    // 指定为拉伸模式,伸缩后重新赋值
    image = [image resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];

     16.在 - (void)viewDidLoad  / - (void)viewWillAppear:(BOOL)animated 获取子控件的大小位置,结果得到的全部都是0

      在viewDidLoad之前,视图控制器的作为view的outlet不和storyboard连接,直到viewWillAppear时,view的体积才被设置。

      这个view的所有维度在layoutSubviews时会被计算和设置,但layoutSubviews是发生在viewWillAppear之后,

      因此,在layoutSubviews之后,才能得到这个view设置在storyboard中的所有维度值。

     17.延长Default.png显示的时间

    -(Bool)application:(UIApplication *)application didFinishLaunchingWithOptions:  (NSDictionary *)launchOptions
    {
       [NSThread sleepForTimeInterval:10];
       .............
    }

     18.如何指定大小,创建系统字体

    UIFont* font = [UIFont systemFontOfSize:12.0f];

     19.我用UIWebView 加载一个url,系统访问网络的小圈出现并在转动,我调用 UIWebView 的 stopLoading,但是系统访问网络的小圈仍然在转动,请问,如何让系统的小圈消失?

    当你的应用程序使用网络时,应当在iPhone的状态条上放置一个网络指示器,警告用户正在使用网络。这时你可以用UIApplication的一个名为networkActivityIndicatorVisible的属性。通 过设置这个可以启用或禁用网络指示器:

    [ UIApplication  sharedApplication].networkActivityIndicatorVisible = NO;    

    有个更好的东西推荐:MBProgressHUD  

     20.code sign error: provisioning profile can't be found

    • Shut down Xcode.
    • Back up the project.pbxproj file.
    • Edit the project.pbxproj file and remove lines of instances where it mentions the old provisioning profile.Restart Xcode and perform a full clean of the project.
      • eg. Delete line:
      • PROVISIONING_PROFILE = "8D024EDA-DC05-40DF-B3EB-536392615EE2";
    • It should then build without warnings.

     

  • 相关阅读:
    CentOS6.5 安装 tomcat
    CentOS6.5 安装 jdk1.7
    CentOS6.5 mysql 5.5安装
    java使用split切割字符串的时候,注意转义字符
    hibernate中设置BigDeCimal的精度
    powerdesinger中建立一个表后,出现Existence of index的警告
    MySQL数据库一个字段对应多个值得模糊查询
    系统收到了多个不同的 Content-Disposition 标头。为了避免遭到 HTTP 响应拆分攻击,这种情况是不允许的。
    下载的文件名字当前时间(精确到秒)+ 随机数
    简单的poi导出excel文件
  • 原文地址:https://www.cnblogs.com/qc0815/p/3158891.html
Copyright © 2011-2022 走看看