我想控制突出顯示時發生在我的UITableViewCell
中的情況。UITableView控件突出顯示時會發生什麼
我知道這是可能的的iOS 6.0,像這樣:
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
但我怎麼做,如果我針對5.0及以上?
我想控制突出顯示時發生在我的UITableViewCell
中的情況。UITableView控件突出顯示時會發生什麼
我知道這是可能的的iOS 6.0,像這樣:
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
但我怎麼做,如果我針對5.0及以上?
如果你有一個自定義的UITableViewCell可以覆蓋
-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
方法,該方法將被調用時,觸摸是倒在小區(highlighted
PARAM將是YES),當觸摸是取消或取消(highlight
參數爲NO)。
此方法也適用於iOS 3.0及更高版本。
在iOS 5上的最好的辦法是用這種方法
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
雖然這種方法被稱爲只有當用戶點擊,然後提起其手指從細胞(如explained here),但我不瞭解5.x和6.x中可用的其他任何方法,您可以使用它們。
是的,我已經嘗試過,但不幸的是我需要它,而手指是在單元格的頂部。不過謝謝。 – WYS
在我的一個項目中,我需要突出顯示我的圖像,立即用戶觸摸單元格,以便在Ios 5.0中實現突出顯示狀態。這些函數都是在自定義單元類中編寫的。根據您的要求修改這些功能。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self hightlightImage];
[self performSelector:@selector(detecetedLongTap) withObject:nil afterDelay:1.0];
[super touchesBegan:touches withEvent:event];
}
-(void)detecetedLongTap{
[self hightlightImage];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
if (titleLabel.textColor == [UIColor blackColor])
[self hightlightImage];
[super touchesEnded:touches withEvent:event];
}
這似乎是最後的手段,如果沒有別的更好。 – WYS
這其實是正確的,上帝我很愚蠢,我沒有想到這一點。我會試試這個。 – WYS