6

私は今、奇妙な問題に取り組んでいます。My Apps Deployment Target は iOS6 に設定されているため、iOS6 と iOS7 の両方をサポートしたいと考えています。

ユーザーが好みの通知音を選択できるシンプルなUITableViewがあります。

コード- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathは次のとおりです。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"CheckmarkCell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
        [cell setTintColor:[UIColor redColor]];
        if (indexPath.section == 0){
            cell.textLabel.text = [_availableSounds objectAtIndex:indexPath.row];
            if (indexPath.row == _checkedSoundIndexPath.row) {
                cell.accessoryType = UITableViewCellAccessoryCheckmark;
            }
        }
        else {
// Unrelated, another settings cell
                cell.accessoryType = UITableViewCellAccessoryNone;
                cell.selectionStyle = UITableViewCellSelectionStyleNone;
            }
            return cell;
        }

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPathは次のように見えます:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section != 0) {
        return;
    }
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    [[self.tableView cellForRowAtIndexPath:indexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
    if (_checkedSoundIndexPath != indexPath) {
        [[self.tableView cellForRowAtIndexPath:_checkedSoundIndexPath] setAccessoryType:UITableViewCellAccessoryNone];
    }
    _checkedSoundIndexPath = indexPath;
}

問題は、iOS7 の iPhone では期待どおりにチェックマークが表示されないことです。iOS6 iPhone で同じコードを実行すると、期待どおりに動作します。挿入しようとしまし[cell setTintColor:[UIColor redColor]];たが、うまくいきませんでした。AccessoriesType 関連のコードをすべて削除して、ストーリーボードにチェックマークを追加しても、何も表示されません。以下のスクリーンショットを参照してください (1 番目は iOS6、2 番目は iOS5 です)。

誰にもアイデアはありますか?それともiOS7のバグですか?

前もって感謝します !

編集:

UITableViewAccessoryTypeCheckmark に設定されたアクセサリを持つ 5 つのセルだけで、新しい単純な UITableViewController を作成しても、iOS7 ではチェックマークが表示されません。

iPhone 4 の iOS6 iPhone 5 の iOS7

4

8 に答える 8

10

同様の問題があり、uitableviewの色合いを変更してこの問題を解決しました

InterfaceBuilder で uitable の tintcolot を Default color に変更しました

また

tableView.tintColor =  [UIColor blackColor];
于 2013-10-16T04:55:35.800 に答える
4

私はあなたとまったく同じ問題を長い間抱えていました。私の場合、いくつかの外観の微調整を実装しました。そしてそのうちの1人は

[[UIView appearance] setTintColor:[UIColor whiteColor]];

そのようなグローバルなものをプロジェクトで見つけてみてください。

于 2013-11-28T15:07:48.930 に答える
2
In my application it working perfect,check it 
//take it in .h file mutable arSelectedRows;
- (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];
    }
   [cell setSelectionStyle:UITableViewCellSelectionStyleGray];

   //Do anything you want for cell here
   if([arSelectedRows containsObject:indexPath]) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
   else {
          cell.accessoryType = UITableViewCellAccessoryNone;
    }
   return cell;
}

 #pragma mark - Table view delegate

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
   UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
   if(cell.accessoryType == UITableViewCellAccessoryNone) {
       cell.accessoryType = UITableViewCellAccessoryCheckmark;
       [arSelectedRows addObject:indexPath];
   }
   else {
      cell.accessoryType = UITableViewCellAccessoryNone;
       [arSelectedRows removeObject:indexPath];
  }
   NSLog(@"id are here :%@",arSelectedIDs);

   [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

かもしれません、参考になります。

于 2013-10-12T12:18:34.733 に答える
0

問題は checksoundIndexpath にあると思います。正しいインデックスパスがあるかどうかを確認してください。または、最初にハードコードされたインデックスパスを確認してください。

あなたはchecksoundindxpathを初期化していません。

また、選択した行の indexpath を _checkSoundIndexpath に割り当てていないことに気付きました。両方の indexpaths (現在の indexpaths と _checksoundindexpath) が等しいかどうかを確認しているだけですが、それらが異なる場合は、選択した indedxpath を _checksound indexpath に割り当てる必要があります。

于 2013-10-17T04:51:34.850 に答える
0

この問題は、セルの色合いを設定することで解決できますセルの色合いが白で、セルの選択スタイルがなしであるため、表示されませんでした

cell.tintColor = [UIColor blackColor];

    if(cell.selected){
        [cell setAccessoryType:UITableViewCellAccessoryCheckmark];
    }else{
        [cell setAccessoryType:UITableViewCellAccessoryNone];

    }
于 2013-10-28T08:51:32.337 に答える
0

元の質問が単純なものを使用していることは知っていますUITableViewCellが、これはカスタム テーブル ビュー セルを使用する他の人にとってはうまくいく可能性があります。

カスタムUITableViewCellサブクラスがあります。すべて試しましたが、チェックマークが表示されません。最終的に、オーバーライドしたことに気づきlayoutSubviewsましたが、 を呼び出すのを忘れていました[super layoutSubviews]。つまり、チェックマークが正しく表示されませんでした。

 - (void)layoutSubviews
{
    [super layoutSubviews];
    //...custom layout here
}
于 2016-11-15T07:44:07.590 に答える
0

reloadRowsAtIndexPathsメソッドで適切なデータを設定した後、テーブルビューをリロードします(できれば影響を受ける行のみを使用して) didSelectRowAtIndexPath:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Other logic..

            [tableView deselectRowAtIndexPath:indexPath animated:NO]; // Would like to look for an alternative method to avoid this refresh??

            NSMutableArray *reloadArray = [NSMutableArray arrayWithCapacity:2];
            [reloadArray addObject:indexPath];

            [reloadArray addObject:_checkedSoundIndexPath];

            self.checkedSoundIndexPath = indexPath;   // Should set this before reload
            [tableView reloadRowsAtIndexPaths:reloadArray withRowAnimation:UITableViewRowAnimationAutomatic];
}

そして、最も重要なことは、次の行を cellForRowAtIndexPath: メソッドに追加することです -

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    // All your other code for this section followed by these lines...

    if([_checkedSoundIndexPath compare:indexPath] == NSOrderedSame) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    }
    else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }

    // Other sections code
    return cell;
}
于 2013-10-17T18:54:25.650 に答える