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


ピックアップ記事

phpで処理を遅延させてから実行する。

2009年12月26日 過去Blog
phpで少し時間をおいてから処理を実行したい場合は、sleepを使います。 例) [php]<?php echo "最初の処理"; //3秒後に実行 sleep(3); //処理再開 echo "遅延後の処理"; ?>[/php]
「phpで処理を遅延させてから実行する。」をはてなブックマークに追加

ユーザーエージェントを調べる方法

2009年11月24日 過去Blog
ユーザーエージェントを調べる方法 javascript:alert(navigator.userAgent) http://katozyun.web.fc2.com/urawaza/ua02.html http://somethinweb.jp/test123/useragent.php また,UAは以下のサイトでも確認することができます. * 診断くん:http://www.t…
「ユーザーエージェントを調べる方法」をはてなブックマークに追加

php 文字列を指定した文字ごとに分割する wordwrap

2010年01月29日 過去Blog
以下のようにすることで、10文字ごとに "n"で区切ることが出来ます。 参照元:http://www.php.net/manual/ja/function.wordwrap.php…
「php 文字列を指定した文字ごとに分割する wordwrap」をはてなブックマークに追加

UIActionSheet を複数使った場合のメソッドの振り分け

2011年05月03日 過去Blog
1つのクラスファイル内で、複数のUIActionSheetを使う時はtagプロパティを使って、どのアクションシートのボタンがクリックされたのかを判別します。 actionsheet.tag = 1; 詳しくは以下のサイトを参照。 http://technical-iphone.blogspot.com/2010/05/uiactionsheet.html
「UIActionSheet を複数使った場合のメソッドの振り分け」をはてなブックマークに追加

mySQL上で登録された内容に一致する文字列を置き換え

2009年12月25日 過去Blog
以下のようにSQLを実行することで該当箇所が置き換えされます。 phpのstr_replaceのような感じ。 UPDATE `テーブル名` SET フィールド名 =REPLACE (フィールド名,"置き換え前文字列","置き換え後文字列"); limo service san diego…
「mySQL上で登録された内容に一致する文字列を置き換え」をはてなブックマークに追加
© graffiti on the web . All rights reserved. WordPress Theme by comfy