---
title: "IOS开发问题集"
author: "zhy584520"
date: "2014-07-28T10:42:44Z"
tags: []
categories: ["移动开发"]
slug: "ios"
draft: false
lastmod: "2014-07-28T10:42:44Z"
id: 2097178
url: "https://zhy584520.iteye.com/blog/2097178"
---

IOS学习问题集

1.UIWebView内嵌在UITableView里，webview内容较少情况，在滚动到web view时，停顿一会滚动条消失，整个tableview就不能滚动问题。

解决办法：

            for (id subView in webView.subviews) {

                if (\[subView isKindOfClass:\[UIScrollView class]]) {

                    UIScrollView \*scroll = (UIScrollView \*)subView;

                    scroll.bounces = NO;

                }

            }

2\. UIWebView内嵌在UITableView里，如何根据web view内容调整web view的高度以及cell的高度？

解决办法：

            UIWebView * webView =\[\[UIWebView alloc]initWithFrame:CGRectMake(0, 20, 320, 100)];

            webView.opaque = NO;

            webView.backgroundColor = \[UIColor clearColor];

            webView.delegate = self;

在webview协议里添加如下代码：

\- (void)webViewDidFinishLoad:(UIWebView \*)webView

{

    CGSize actualSize = \[webView sizeThatFits:CGSizeZero];

    CGRect newFrame = webView.frame;

    newFrame.size.height = actualSize.height;

    webView.frame = newFrame;

    NSString \*string = \[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"];

    \_webHeight = \[string floatValue]+20;

    \[self.tableView beginUpdates];

    \[self.tableView endUpdates];

}

3.UITextField全选问题，当调用UITextField selectAll 方法时，正常情况下都是可以全选的，可是当不改变UITextField内容时，点击其它UITextField再返回到原来的UITextField时，再调用selectAll时就会不起作用，原因不清楚，可能是苹果为了优化的考虑？

解决办法：

        \[textField selectAll:textField];

        [textField setMarkedText:textField.text

                   selectedRange:NSMakeRange(0,0)];

如果想让UITextField获取焦点时，隐藏光标的方法如下：

// hide cursor (you have store default color!!!)

\[\[textField valueForKey:@"textInputTraits"] setValue:\[UIColor clearColor]

                                       forKey:@"insertionPointColor"];

本博文持续更新中.....