我正試圖在Objective-C中隱藏Speakrbox代碼。 我已經轉換的大部分代碼,但是我有一個小問題,這一個:從Swift到Objective C - updateCallDurationForVisibleCells
private func updateCallDurationForVisibleCells() {
/*
Modify all the visible cells directly, since -[UITableView reloadData] resets a lot
of things on the table view like selection & editing states
*/
let visibleCells = tableView.visibleCells as! [CallSummaryTableViewCell]
guard let indexPathsForVisibleRows = tableView.indexPathsForVisibleRows else { return }
for index in 0..<visibleCells.count {
let cell = visibleCells[index]
let indexPath = indexPathsForVisibleRows[index]
guard let call = call(at: indexPath) else { return }
cell.durationLabel?.text = durationLabelText(forCall: call)
}
}
我試着將它轉換,這裏是我:
-(void) updateCallDurationForVisibleCells :(id)sender {
/*
Modify all the visible cells directly, since -[UITableView reloadData] resets a lot
of things on the table view like selection & editing states
*/
_visibleCells = _tableview.visibleCells;
if(_indexPathsForVisibleRows == _tableview.indexPathsForVisibleRows) { return ; }
int index;
for (index=0; index<_visibleCells.count; index ++)
{
UICollectionViewCell *cell = _visibleCells[index];
NSIndexPath *indexPath = _indexPathsForVisibleRows[index];
UITableViewCell* call;
if((call = [self.tableView cellForRowAtIndexPath:indexPath]))
{ return ; }
}
}
可以在任何一個請幫我把這個Swift代碼轉換成Objective-C?該代碼不編譯的原因,我不知道怎麼這行代碼轉換:
cell.durationLabel?.text = durationLabelText(forCall: call)
另外,我不知道我是否以正確的方式做到了,尤其是轉換guard let
。
,你會發現這裏呼叫和durationLabelText功能,我在pdateCallDurationForVisibleCells功能已經使用:
private func call(at indexPath: IndexPath) -> SpeakerboxCall? {
return callManager?.calls[indexPath.row]
}//swift
private func durationLabelText(forCall call: SpeakerboxCall) -> String? {
return call.hasConnected ? callDurationFormatter.format(timeInterval: call.duration) : nil
}//Swift
請[編輯]你的問題,並清楚地解釋發出您有用你發佈的代碼。 – rmaddy
你不明白如何工作'警衛let':'if(_indexPathsForVisibleRows == _tableview.indexPathsForVisibleRows){return; }'=>'if(!_tableview.indexPathsForVisibleRows){return;}'對於'guard let call = call(at:indexPath)else {return}',我不知道'call'是什麼。 – Larme
@Rmaddy我試圖將一個快捷方法轉換爲目標c,第一個代碼是在swift中,第二個是我已經實現它的結果比swift快的那個objectivec代碼 – khouloud