私はaddSubviewを使って部分的にカスタムであるセルを持つUITableViewを持っています。私は新しいセルを表示させるサーバーからより多くのデータを読み込むことを目的とした、最後のセルに別のセルIDを使用しています。 (Mail.appの「サーバーからのメッセージをもっと読み込む」と思ってください)非常に迅速にタップすると、UITableViewCell選択が描画されないのはなぜですか?
例:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// <... code for normal cells omitted...>
static NSString *LoadMoreCellIdentifier = @"LoadMoreCellIdentifier";
UILabel *loadMoreLabel;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LoadMoreCellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:LoadMoreCellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
loadMoreLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, cell.frame.size.width, self.tableView.rowHeight - 1)] autorelease];
loadMoreLabel.tag = LOAD_MORE_TAG;
loadMoreLabel.font = [UIFont boldSystemFontOfSize:16.0];
loadMoreLabel.textColor = [UIColor colorWithRed:0.153 green:0.337 blue:0.714 alpha:1.0]; // Apple's "Load More Messages" font color in Mail.app
loadMoreLabel.textAlignment = UITextAlignmentCenter;
[cell.contentView addSubview:loadMoreLabel];
}
else
{
loadMoreLabel = (UILabel *)[cell.contentView viewWithTag:LOAD_MORE_TAG];
}
loadMoreLabel.text = [NSString stringWithFormat:@"Load Next %d Hours...", _defaultHoursQuery];
return cell;
}
上記のように、cell.selectionStyle = UITableViewCellSelectionStyleGrayを設定します。あなたはセルをタップすると
、私はそうのような選択を解除:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (_showLoadMoreEntriesButton && indexPath.row == [_sourceArray count])
{
// <... omitted...>
// Do a potentially blocking 1 second operation here to obtain data for more
// cells. This will potentially change the size of the _sourceArray
// NSArray that acts as the source for my UITableCell
[tableView deselectRowAtIndexPath:indexPath animated:NO];
[self.tableView reloadData];
return;
}
[tableView deselectRowAtIndexPath:indexPath animated:NO];
[self _loadDataSetAtIndex:indexPath.row];
}
私が見ている問題は、私は灰色のハイライトが表示されるようにするには私の指を下にタップし、保持するために持っていることです。私が非常に素早くタップすると、ハイライトを全く表示しません。問題は、時には1秒ほどかかるブロッキング操作を実行することがあることです。 UIをロックするのではなく、何かが起こっているという簡単なUIフィードバックがほしい。インデックスパスがテーブルの最後の行であるかどうかを条件付きでチェックすることに関連していると思います。
毎回ハイライトを描画する方法を知りたいですか?
私は何も処理したくないので、セル選択を常に表示したいだけです。私はそれが応答しないことを理解します。 – Jeremy
コードがメインスレッドでブロックされている場合は、UIスレッドが更新してユーザーの入力に応答するために必要な処理は行われません。スレッドを使用する以外にもその方法はありません。 –
それは良い点です。非同期のものを試してみるべきだと思います。 – Jeremy