なぜこれが問題になるのかわかりませんが、うまく機能させるのに苦労しています。
免責事項: これは私の最初の iOS アプリです (または、Apple で開発したものであり、アプリは昨日完成させる必要があるため、急ぎのコードはご容赦ください)。
SWRevealViewController ライブラリを使用して、ホーム ビュー ナビゲーション コントローラーのボタンがクリックされたときに、Facebook 風の "サイド ビュー" を作成しています。それはうまく機能します、それを愛してください。このビューは、静的セルが 2 つしかない UITableView を保持しており、ビューの一番下にセルを追加するリクエストを受け取りました。
その 3 番目のセルを UITableView の「中に」取得しようとするのは明らかではなかったので、私の xib では、UITableView の外側に UITableViewCell を作成し、それをビューの下部に配置しました。次に、標準の IBOutlet ワークフローを使用してコントローラーに接続しました。
viewDidLoad に戻り、不正なセルをスキンして残りのテーブルセルのように見せ、言葉遣いを追加し、クリックすると会社の Web サイトが開くようにするハンドラーを追加しましたが、すべて正常に動作しました。tableView:cellForRowAtIndexPath 関数の「通常の」テーブル セルに対して、これらすべてを実行しました。
しかし、何らかの理由でセルをクリックすると、クリックしたときに他の通常のセルのように強調表示されません! どうして!
コード:
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
} else {
[[cell.contentView viewWithTag:1] removeFromSuperview];
}
UILabel *lblView = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 3.0, 187.0, cell.frame.size.height)];
[lblView setFont:[UIFont fontWithName:@"FuturaStd-Bold" size:12]];
lblView.textColor = [UIColor colorWithRed:(255/255.f) green:(241/255.f) blue:(204/255.f) alpha:1.0];
lblView.tag = 1;
if (indexPath.row == 0){
[lblView setText:@"SCHEDULE"];
} else if (indexPath.row == 1){
[lblView setText:@"SPEAKERS"];
}
lblView.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:lblView];
UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 277, 58)];
av.backgroundColor = [UIColor clearColor];
av.opaque = NO;
av.image = [UIImage imageNamed:@"blackBar.png"];
cell.backgroundView = av;
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor colorWithRed:(240/255.f) green:(145/255.f) blue:(62/255.f) alpha:1.0]];
[cell setSelectedBackgroundView:bgColorView];
return cell;
}
上記のコードは、私の「通常のセル」では正常に機能します。セルを返す前の最後のビットは、「クリックされている」ときに背景を奇妙なオレンジ色で強調表示するように設定するものです。
以下のコードは同じものですが、私のviewDidLoadでは、クリックされたときに背景のハイライト色を設定していません。
- (void)viewDidLoad
{
[super viewDidLoad];
//... stuff
UILabel *lblView = [[UILabel alloc] initWithFrame:CGRectMake(20.0, 3.0, 187.0, _roguecell.frame.size.height)];
[lblView setFont:[UIFont fontWithName:@"FuturaStd-Bold" size:12]];
lblView.textColor = [UIColor colorWithRed:(255/255.f) green:(241/255.f) blue:(204/255.f) alpha:1.0];
[lblView setText:@"IT'S A SECRET LOL"];
lblView.backgroundColor=[UIColor clearColor];
[_roguecell.contentView addSubview:lblView];
UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 277, 58)];
av.backgroundColor = [UIColor clearColor];
av.opaque = NO;
av.image = [UIImage imageNamed:@"blackBar.png"];
_roguecell.backgroundView = av;
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor colorWithRed:(240/255.f) green:(145/255.f) blue:(62/255.f) alpha:1.0]];
[_roguecell setSelectedBackgroundView:bgColorView];
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[_roguecell addGestureRecognizer:singleFingerTap];
}
たぶん、それは私のxibファイルと関係があり、UITableViewがビュー全体に拡張されており、不正なUITableViewCellがその「上」にあります(ただし、明らかにそうではありません)。テーブルとセルの場所をいじってみましたが、何もしませんでした。
読んでくれてありがとう。