非同步傳輸取得網路資料, 透過請求方式等待server回傳資料
此範例為將接收到的資料顯示於UIImageView上, 並且透過Button點擊事件觸發非同步傳輸與顯示圖片事件
非同步傳輸可避免取得資料會有稍微停頓之問題
Will 發表在 痞客邦 留言(0) 人氣(329)
同步傳輸取得網路資料, 透過請求方式等待server回傳資料
此範例為將接收到的資料顯示於UIImageView上, 並且透過Button點擊事件觸發同步傳輸與顯示圖片事件
- (IBAction)getDataBtnClick:(id)sender {
/*儲存欲取得之路徑並指定給urlString*/
NSString *urlString = @"輸入網路圖片之路徑";
/*建立NSURL request物件設定請求內容*/
NSURLRequest *request =
[NSURLRequestrequestWithURL:[NSURLURLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
cachePolicy:NSURLRequestReloadIgnoringCacheDatatimeoutInterval:60.0f];
/*設定同步請求*/
NSData *returnData = [NSURLConnectionsendSynchronousRequest:
request returningResponse:nilerror:nil];
/*透過UIImageView顯示一開始設定的網路圖片*/
_myImageViw.image=[UIImageimageWithData:returnData];
}
Will 發表在 痞客邦 留言(0) 人氣(159)
同步傳輸取得網路資料, 透過請求方式等待server回傳資料
此範例為將接收到的資料轉換為字串格式, 並且透過Button點擊事件觸發同步傳輸事件
- (IBAction)getDataBtnClick:(id)sender {
/*儲存欲取得之路徑並指定給urlString*/
NSString *urlString = @"http://yahoo.com.tw";
/*建立NSURL request物件設定請求內容*/
NSURLRequest *request =[NSURLRequestrequestWithURL:[NSURLURLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]
cachePolicy:NSURLRequestReloadIgnoringCacheDatatimeoutInterval:60.0f];
/*設定同步請求*/
NSData *returnData = [NSURLConnectionsendSynchronousRequest:
request returningResponse:nilerror:nil];
/*接收到的資料NSData格式無法直接閱讀, 所以還要做編碼動作轉換成字串格式*/
NSString *returnString =[[NSStringalloc]initWithData:
returnData encoding:NSUTF8StringEncoding];
NSLog(@"%@", returnString); //將字串印出
}
Will 發表在 痞客邦 留言(0) 人氣(67)
上一篇提到的簡易型與傳統型處理機制,
其中最大的分別在於簡易型只能用於元件被觸擊的事件處理情況,
而傳統型可用於多種情況, 不只用於觸擊事件,
例如下拉式選單改建 or 其他事件之處理等等, 都可以採用傳統型處理機制
MainActivity.java
Will 發表在 痞客邦 留言(0) 人氣(33)
在layout XML檔中設定button, 並在properties欄位中的on click設定呼叫之方法名稱,
此種事件處理為簡化行處理機制,
此範例中設定此方法名稱為toShowToast,
點擊之後取得按鈕text內容並且用toast方塊顯示
MainActivity.java
Will 發表在 痞客邦 留言(0) 人氣(94)
原文解釋: used to agress to what someone wants and to say
that it will be no problem likes dont worry.
or you are welcome in Aus.
Will 發表在 痞客邦 留言(2) 人氣(710)
inside out
原文解釋: with the usual outside parts on the inside, or know something so much
中文解釋: 由內朝外, 或者 對某事徹底了解
已下為三個例句:
Will 發表在 痞客邦 留言(0) 人氣(170)
cathc my breath
原文解釋: to need time to breath, or to get ready / prepare
中文解釋: 喘口氣, 或者給予時間去備妥某事, 或屏息以待
已下為三個例句:
Will 發表在 痞客邦 留言(2) 人氣(897)
save your breath
原文解釋: used to say someone will not be able to persude someone else,
or you already knew the information.
中文解釋: 省省力氣, 別做白費力氣的嘗試, 或者用於已經知道這消息
已下為兩個例句:
Will 發表在 痞客邦 留言(0) 人氣(402)
don't hold your breath
原文解釋: used to say that something is not going to happen soon,
or don't expect too much because you never know what the outcome might been.
中文解釋: 別抱太大期望
已下為三個例句:
Will 發表在 痞客邦 留言(0) 人氣(2,525)