![](/img/trans.png)
[英]Highlighting table view cell will not highlight subviews of table view cell using objective-C
[英]Highlight long pressed table view cell and unhighlight in iOS using objective-C
長按突出顯示表格視圖單元格。
我提到了鏈接
長按效果良好,但表格視圖單元格未突出顯示。 所以我將以下行添加到handleLongPress方法
[self.myTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
在長按單元格突出顯示之后,還應滿足以下條件,
長按的行為應類似於觸摸表格單元格,但不應該是實際的觸摸功能。 請指導我。
嘗試:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
請使用此類邏輯。 當您開始長按時,將顯示選定的行,而長按結束時則必須取消選擇行。
-(IBAction)longPressBegan:(UILongPressGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateBegan)
{
// Long press detected, Just highlight row
}
else
{
if (recognizer.state == UIGestureRecognizerStateCancelled
|| recognizer.state == UIGestureRecognizerStateFailed
|| recognizer.state == UIGestureRecognizerStateEnded)
{
// Long press ended, deselect row
}
}
}
希望這會幫到你...........
因此,我認為您的所有條件僅在您長時間按下某個單元格的情況下才會發生。 看來您可以進行長時間的宣傳。 所以現在
在長按事件中添加
[self.myTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; YourCell *cell = [self.myTableView cellForRowAtIndexPath:indexPath]; //I dont't know your model for this tableview so I am using cell tag for it //using 1 for selected //2 for unselected // 3 for long pressed one cell.tag = 3; isHiglighted = YES;
在didSelectRowAtIndexPath中使用以下sudo代碼
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if(isHiglighted) { YourCell *cell = [self.myTableView cellForRowAtIndexPath:indexPath]; if(cell.tag==3) { [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; cell.tag = 2; isHiglighted = NO; } else if(cell.tag==1) { [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; cell.tag = 2; } else { [self.myTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; cell.tag = 1; } } else { // do your stuff ofr single tap if user never long pressed } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.