2011年01月03日 過去Blog
tableView に関する設定の説明です。 テーブル内のセクション数を設定する 以下の例では、2つのセクションをもつテーブルになります。

– (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

return 2;

}

セクション内の行数を指定する 以下の例では、最初のセクションは、2行のデータを表示し、次のセクションでも2行のデータを表示します。

– (NSInteger)tableView:(UITableView *)tableView

numberOfRowsInSection:(NSInteger)section {

if (section == 0) {

return 2;

}

else if(section == 1){

return 2;

}

return [listOfGameMode count];

}

各セルの表示内容の設定「セルを生成(初期化)する時に呼ばれる」 以下の例では、最初のセクションの最初の行のテキストに”yamazon”と表示し、次の行に、”webTipsAroundMe”と表示します。同様に、二つ目のセクションには、”iPhoneApp”、”objective-C”と表示します。return の前の行は、各セルの背景を赤に設定しています。

– (UITableViewCell *)tableView:(UITableView *)tableView

cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @”Cell”;

UITableViewCell *cell = [tableView

dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc]

initWithStyle:UITableViewCellStyleDefault

reuseIdentifier:CellIdentifier]

autorelease];

}

// NSString *cellValue = [listOfGameMode objectAtIndex:indexPath.row];

// cell.textLabel.text = cellValue;

if(indexPath.section == 0) {

if(indexPath.row == 0) {

cell.textLabel.text = @”yamazon”;

} else if(indexPath.row == 1){

cell.textLabel.text = @”webTipsAroundMe”;

}

} else if(indexPath.section == 1) {

if(indexPath.row == 0) {

cell.textLabel.text = @”iPhoneApp;

} else if(indexPath.row == 1){

cell.textLabel.text = @”objective-C;

}

}

cell.contentView.backgroundColor = [UIColor redColor];

return cell;

}

各セルの表示内容の設定「セルを表示する時に呼ばれる」 上記のメソッドと少し使い分けがややこしいですが、各セルの背景色などを設定するには以下のように「willDisplayCell」メソッドで実装したほうが良いようです。以下のメソッドでは、各奇数セルは背景色を白にし、偶数セルは、UIColorで指定した色(薄い水色)に設定しています。

– (void)tableView:(UITableView *)tableView

willDisplayCell:(UITableViewCell *)cell

forRowAtIndexPath:(NSIndexPath *)indexPath

{

if (indexPath.row % 2 == 0) {

cell.backgroundColor = [UIColor whiteColor];

}

else {

cell.backgroundColor = [UIColor colorWithHue:0.61

saturation:0.09

brightness:0.99

alpha:1.0];

}

}

セクションのヘッダーのタイトルを設定 以下の例では、最初のセクションでは、yamazonという文字がセクションのヘッダー部に表示されます。その他のセクションでは、WTAMが表示されます。

– (NSString *)tableView:(UITableView *)tableView

titleForHeaderInSection:(NSInteger)section{

if(section == 0) {

return @”yamazon”;

}

return @”WTAM;

}

セクションのフッター部のタイトルを設定 以下の例では、セクションのフッター部にFooterという文字列が表示されます。

– (NSString *)tableView:(UITableView *)tableView

titleForFooterInSection:(NSInteger)section {

return @”Footer”;

}

セルが選択された時の設定

– (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:

(NSIndexPath *)indexPath {

}

セクションのヘッダー部の設定

– (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

}

セクションのヘッダーの高さを設定

– (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

return 30;

}

各行の高さの設定

– (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

if (indexPath.section == 0) {

if(indexPath.row == 0) {

return 80; // 一番上のセクションの一番上の行の高さは80ピクセルにします。

}

} else if (indexPath.section == 1) {

return 60; // 二番目のセクションの行の高さは全て60ピクセルにします。

}

return 45; // 上で指定しなかった全てのセクション・行の高さは全て45ピクセルにします。

}

この投稿へのコメント

コメントはまだありません。

コメントを残す

メールアドレスが公開されることはありません。

次のHTML タグと属性が使えます。
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CAPTCHA


ピックアップ記事

サーバの時刻調整

2010年03月05日 過去Blog
サーバの時刻設定 1. 時刻確認 date 2. 時刻設定 date -s "2006/02/20 19:03" linux上で、上記のコマンドを実行すれば、調整出来ます。 参照元:http://memorva.jp/memo/linux/date_ntp.php buy anabolics online…
「サーバの時刻調整」をはてなブックマークに追加

PHPでPING送信を実装する

2010年03月28日 過去Blog
[php]<?php require_once('XML/RPC.php'); function Ping_Send($blog_title,$blog_url){ $ping = array( 'ping.rss.drecom.jp' => '/', 'api.my.yahoo.co.jp' => '/RPC2', 'blog.goo.n…
「PHPでPING送信を実装する」をはてなブックマークに追加

[11] NSUserDefaults を使ってデータを保存・取り出し

2010年12月20日 過去Blog
このチュートリアルでは、各種データをNSUserDefaultsを使って、保存、抽出する方法について説明します。 NSUserDefaults は、データベースの知識を必要としないので、SQLite3のようなデータベースを必要としない(ゲームのハイスコア、ログイン情報、アプリの設定など)、小規模のデータを扱う場合には便利で簡単です。 今回は、例として、初回時にアプリを起動し、名前を入力すると、保存され、次回以降の起動時には、保存された名前が自動的に名前が表示されるアプリケーションを作成します。 …
「[11] NSUserDefaults を使ってデータを保存・取り出し」をはてなブックマークに追加

MODx vs Drupal ?

2009年11月18日 過去Blog
今まで何度もCMSのMODxを使う事があったので、使い慣れているのもあり、なかなかお気にいりのCMSなのですが、最近少し気になるのがdrupal・・・・ MODx同様、日本では、情報も少なく、あまり浸透もしてないようですが、一度インストールして使ってみようかなぁ。。。…
「MODx vs Drupal ?」をはてなブックマークに追加

iPhone アプリにアイコンを設定する

2010年12月09日 過去Blog
自作のiPhoneアプリにアイコンを設定する方法です。 まず、アイコンに使いたい画像を準備します。 画像サイズ 57px × 57px アイコン画像の設定 (1)プロジェクト内のResourceフォルダを右クリックし、既存のファイルを追加を選びます。そして、準備しておいた画像を選択、このとき表示される画面ないの「デスティネーション...」の項目をチェックし、追加します。 (2)その後、プロジ…
「iPhone アプリにアイコンを設定する」をはてなブックマークに追加
© graffiti on the web . All rights reserved. WordPress Theme by comfy