UITableのセルに新着を表示させる。

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
marucom

UITableのセルに新着を表示させる。

#1

投稿記事 by marucom » 13年前

UITableのセルに新着ボタンを表示させ、一度選択したらそのボタンを非表示にする方法を教えてください。
表示させるボタンの生成は出来たのですが、選択後非表示に出来ません。
下記に新着ボタンのコードを記載します。



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"badegedCell";
TDBadgedCell *aCell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (aCell == nil) {
aCell = [[TDBadgedCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:identifier];
}


// 設定する内容をNSStringで渡す。
aCell.badgeString = [NSString stringWithFormat: @"新着"];
// 色の指定
aCell.badgeColor = [UIColor colorWithRed:0.8 green:0.2 blue:1.0 alpha:1.0];
// 丸みの指定
aCell.badge.radius = 9;
// 陰の指定
// Cell選択時にハイライトになった際に、陰を表示する。
aCell.showShadow = YES;

 return aCell;
}

アバター
h2so5
副管理人
記事: 2212
登録日時: 15年前
住所: 東京
連絡を取る:

Re: UITableのセルに新着を表示させる。

#2

投稿記事 by h2so5 » 13年前

セルにバッジを表示するかどうかのフラグを作って、

コード:

if (flag) {
    aCell.badgeString = [NSString stringWithFormat: @"新着"];
    aCell.badgeColor = [UIColor colorWithRed:0.8 green:0.2 blue:1.0 alpha:1.0];
    aCell.badge.radius = 9;
    aCell.showShadow = YES;
} else {
    // バッジを表示しない
    aCell.badgeString = nil;
}
のようにしてバッジの表示を切り替えます。

選択した時の処理は didSelectRowAtIndexPath メソッドで設定できますから、
そこでフラグをOFFにしてTableViewをリロードすれば良いでしょう。

marucom

Re: UITableのセルに新着を表示させる。

#3

投稿記事 by marucom » 13年前

ありがとうございます。

>選択した時の処理は didSelectRowAtIndexPath メソッドで設定できますから、
そこでフラグをOFFにしてTableViewをリロードすれば良いでしょう。

とありますが、下記にどのような形でコードを記載てよいのかわかりません。
もしよろしければ、詳細をご返信いただければと思います。

[CODE

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {




if (indexPath.row == 0) {
Story1ViewController *svc = [[Story1ViewController alloc] initWithNibName:@"Story1ViewController" bundle:nil];
svc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:svc animated:YES];

}

if (indexPath.row == 1) {
Story2ViewController *s2vc = [[Story2ViewController alloc] initWithNibName:@"Story2ViewController" bundle:nil];
s2vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:s2vc animated:YES];

}
if (indexPath.row == 2) {
Story3ViewController *s3vc = [[Story3ViewController alloc] initWithNibName:@"Story3ViewController" bundle:nil];
s3vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:s3vc animated:YES];

}

if (indexPath.row == 3) {
Story4ViewController *s4vc = [[Story4ViewController alloc] initWithNibName:@"Story4ViewController" bundle:nil];
s4vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:s4vc animated:YES];

}


}
]

アバター
h2so5
副管理人
記事: 2212
登録日時: 15年前
住所: 東京
連絡を取る:

Re: UITableのセルに新着を表示させる。

#4

投稿記事 by h2so5 » 13年前

まずバッジを表示するかどうかを管理するフラグを作りましょう。
配列をTableViewのメンバとして実装するというのはどうでしょうか。

また、上記のコードはもっと簡潔に書くことができます。

コード:

UIViewController *svc = nil;

switch (indexPath.row) {
    case 0:
        svc = [[Story1ViewController alloc] initWithNibName:@"Story1ViewController" bundle:nil];
        break;
    case 1:
        svc = [[Story2ViewController alloc] initWithNibName:@"Story2ViewController" bundle:nil];
        break;
    case 2:
        svc = [[Story3ViewController alloc] initWithNibName:@"Story3ViewController" bundle:nil];
        break;
    case 3:
        svc = [[Story4ViewController alloc] initWithNibName:@"Story4ViewController" bundle:nil];
        break;
}

svc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:svc animated:YES];

marucom

Re: UITableのセルに新着を表示させる。

#5

投稿記事 by marucom » 13年前

ご教授ありがとうございます。
記載していただいたコードですと、エラーが出てはしまいましたが、if文ではなくswichを使うというヒントをいただけましたので
活用させていただきます。

閉鎖

“C言語何でも質問掲示板” へ戻る