2017-10-06 1 views

답변

0

당신은 다음과 같이 사용할 수 있습니다

var lastSelectedIndexPath: IndexPath? 

func viewDidLoad() { 
    Timer.scheduledTimer(timeInterval: 2.0, target: self, selector: #selector(timerFunc), userInfo: nil, repeats: true) 
} 
@objc func timerFunc() { 
    if lastSelectedIndexPath != nil { 
     tableView(self.table, didUnhighlightRowAt: lastSelectedIndexPath!) 
    } 
    tableView(self.table, didHighlightRowAt: IndexPath(row: YOUR_ROW, section: YOUR_SECTION)) 
} 

func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) { 
    let cell = tableView.cellForRow(at: indexPath) 
    cell?.backgroundColor = UIColor.red 
    lastSelectedIndexPath = indexPath 
} 

func tableView(_ tableView: UITableView, didUnhighlightRowAt indexPath: IndexPath) { 
    let cell = tableView.cellForRow(at: indexPath) 
    cell?.backgroundColor = UIColor.clear 
} 
0

나는이 질문에 대한 나의 이해를 바탕으로이 질문에 대답하고 있습니다. 약간의 시간이 지난 후에 테이블 뷰 셀을 강조 표시한다고 가정합니다.

[NSTimer scheduledTimerWithTimeInterval:2.0 
    target:self 
    selector:@selector(targetMethod:) 
    userInfo:nil 
    repeats:YES]; 


- (void)targetMethod { 
NSIndexPath *defaultIndexPath = [NSIndexPath indexPathForRow:Any_Row_Number inSection:Any_Section_Number]; 
[self tableView:[self tableView] didSelectRowAtIndexPath:defaultIndexPath]; 
} 
관련 문제