網頁

2012年11月26日 星期一

iOS開發筆記-橫向model mode啟動

花了一整個晚上的時間查這長久困擾我的問題,就是presentModalViewController似乎無法在橫向時使用,不甘心決定花時間下去找出問題,心中一直想著是否是viewController無法取得,若是,那要如何取得,最後終於找到方法,我的直覺是對的,取得ViewController的方法也很簡單

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
//上述的AppDelegate指的是在建立整個專案時,那個唯一的ApplicationDelegate
appDelegate.viewController <-- 就是目標viewController


所以整個code如下,就用下面這幾行就搞定了:
UIViewController *file = [[UIViewController alloc] ......];
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

[appDelegate.viewController presentModalViewController:file animated:YES]
[file release];


這花了我一堆時間,我還是太嫩....

參考網址:
iOS模态窗口的实现。(横屏问题)

2012年11月23日 星期五

iOS開發筆記-WebView中點擊link直接開browser以及放在UIScroll中會有的問題

有個需求
  1. 在一個上View載入不知多長的網頁,不要用到WebView的scroll
  2. 點擊上面的link,是開browser瀏覽

基本上在UIWebView Class Reference提到
Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.

不過還是有人提出方法解決,用以下的方式就可以解,可能只是walk around的方式,不過用了至少可以達到我要的需求
webView.opaque = YES;

可以放在UIScroll下後,就解決長度問題,可以用iOS開發筆記-動態更動UIWebView的長度,達到第一個需求

再來第二個,保有WebView目前在看的,要看內容開瀏覽器,在WebViewDelegate中有個function:
(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
可以達到這要求

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        [[UIApplication sharedApplication] openURL:[request URL]];
        return NO;
    }
    return YES;

}

紅字部分就是要求另開app打開url,由os自動決定(似乎就是看預設是哪個app開啟)

參考網址:
UIWebView cannot click link
iPhone: After UIWebView opens external browser, then retruning to app opens it a second time

另外:

2012年11月21日 星期三

iOS開發筆記-動態更動UIWebView的長度

需求:一次載入網頁,動態更動UIWebView的長度

使用UIWebViewDelegate中提供的- (void)webViewDidFinishLoad:(UIWebView *)aWebView,程式碼如下:

- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
    CGRect frame = aWebView.frame;
    CGSize fittingSize = [aWebView sizeThatFits:CGSizeZero];
    frame.size = fittingSize;
    aWebView.frame = frame;

 
    [self setContentSize:CGSizeMake(self.contentSize.width, self.contentSize.height + fittingSize.height)];
}


我在這邊使用的self是個UIScroll,所以直接設定ContentSize的長寬,這樣就行了

參考網址:
How to determine the content size of a UIWebView?

Spring、J2EE學習筆記-數字百分比呈現,是double? int?

不知道是不是太久沒寫java的程式了,今天只是想寫個呈現百分比的字串,結果....嗯~先這樣講好了,我寫成以下樣子

int x = 20;
int y = 100;
double z = x / y;
Numberformat nf = Numberformat.getPercentInstance();
nf.setMinimumFractionDigits(2);
Sytem.out.println(nf.format(z));

結果是:0.00%

一看就知道是有問題的 orz,改成底下這樣子


double x = 20;
double y = 100;
double z = x / y;
Numberformat nf = Numberformat.getPercentInstance();
nf.setMinimumFractionDigits(2);
Sytem.out.println(nf.format(z));

結果是:20.00%


這....我該說是我沒注意,還是compiler或run time是要寫明....

2012年11月20日 星期二

Spring、J2EE學習筆記-中文在input傳送的亂碼問題

在J2EE中,傳送input資料時,預設是使用ISO-8895-1編碼,英文傳送是沒問題,但中文傳送就會變成亂碼,解決方式就是在tomcat的server.xml中,收

<Connector SSLEnabled="true" clientAuth="false" keystoreFile="/XXX/.key" keystorePass="AAAA" maxThreads="150" port="8443" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLS" />

改成

<Connector SSLEnabled="true" clientAuth="false" keystoreFile="/XXX/.key" keystorePass="AAAA" maxThreads="150" port="8443" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLS" URIEncoding="UTF-8" />

不過,在我的狀況,是用8443,若我使用跟參考網址一樣的8080的那個部分,中文一樣會亂碼,猜測這部分也是要看你實際使用的port

參考網址:
http://wenku.baidu.com/view/4148a2e8f8c75fbfc77db25e.html