HTTPでファイルを取得する方法を調べていたら、
少し混乱したので、整理もかねてひな形を保存しておく。
まずはひな形、基本これをコピーして、URLの入力の部分をゴニョゴニョすれば、
一連のDelegateが発火する……ハズ。
// アクション契機のURLリクエスト開始処理
- (IBAction)urlRequest:(id)sender {
NSString* urlStr = urlField.text;
if ( [urlStr length] <= 0 ) {
return;
}
NSURL* url = [NSURL URLWithString:urlStr];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[NSURLConnection connectionWithRequest:request delegate:self];
}
#pragma mark NSURLConnection delegate implementations
// Request送るよ。
- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response {
return request;
}
// 応答受信
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
}
// データ受信
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
}
// キャッシュがするよ
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse {
return nil;
}
// 読み込み完了
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
}
// エラー
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
}
この実装の気に入らないところは、NSURLConnectionに対してDelegateを設定しているというのに、selfのクラス宣言で、プロトコルの実装宣言が要らないところだ。
要らないなら、手間が省けるじゃないかとう意見もあるが、少数の例外が存在するというのは、いろいろ疑う余地が増えてくるので、気持ちのいいものではない。
とわ言え、動くものは動く、とりあえずはソレでヨシとする。
iPhone/iPod touch/iPadアプリ 開発/サポート & 日々のつれづれ
(This blog does the iPhone/iPod touch/iPad application development and support, and occasional scribble away.)
2011/04/26
2011/04/23
UITableViewのひながた。
UITableViewは便利だ。
普通に使うぶんにはレイアウトはFrameWorkにお任せでOK。
こっちは内部の動きに専念できる。
だが、Delegateの実装が必須になる、これをいちいち覚えておくのは面倒クサイ。
なので、必要最低限のひな形を載せておく。
ただし、ヘッダー側にもそれ用の宣言が必要になる。
以下、ひな形
#pragma mark UITableViewDataSource Implementation
// tableのsection数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// section中の行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
// Cell表示
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return nil;
}
// sectionヘッダタイトル
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return nil;
}
#pragma mark UITableViewDelegate Implementation
// 行選択
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
普通に使うぶんにはレイアウトはFrameWorkにお任せでOK。
こっちは内部の動きに専念できる。
だが、Delegateの実装が必須になる、これをいちいち覚えておくのは面倒クサイ。
なので、必要最低限のひな形を載せておく。
ただし、ヘッダー側にもそれ用の宣言が必要になる。
以下、ひな形
#pragma mark UITableViewDataSource Implementation
// tableのsection数
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// section中の行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
// Cell表示
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
return nil;
}
// sectionヘッダタイトル
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return nil;
}
#pragma mark UITableViewDelegate Implementation
// 行選択
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
2011/04/21
UnlockMe 1.1.0 アップデートしました。
登録:
投稿 (Atom)
