처음에는 indexpath가 0,1,2 ...의 순서로 호출되지만, 테이블 뷰를 클릭하면 func tablview가 완전히 무작위로 나타나는 indexpath와 함께 호출됩니다. 따라서 동일한 데이터를 재현 할 수 없습니다. 배열을 사용하여 테이블의 행을 서로 연관시킵니다. 스위프트 : cellForRowAtIndexPath가 indexPaths의 순서로 호출되지 않음
코드
은 여기에 있습니다 :// MARK: - Table view data source
override func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
// #warning Potentially incomplete method implementation.
// Return the number of sections.
return 1
}
override func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete method implementation.
// Return the number of rows in the section.
return myList.count
}
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
// Configure the cell...
println("table view --> ")
let CellID : NSString = "Cell"
var cell : UITableViewCell = tableView?.dequeueReusableCellWithIdentifier(CellID)as UITableViewCell
var VehicleName = cell.viewWithTag(1) as UILabel
var VehicleNumber = cell.viewWithTag(2) as UILabel
if let ip = indexPath
{
VehicleName.text = arrayData[ip.row*2];
VehicleNumber.text = arrayData[ip.row*2+1];
}
}
return cell
}
왜 indexPaths를 주문 하시겠습니까? 또한 잘못된 함수 이름이 많이 언급됩니다. 여기에서 달성하기를 원하는 것, 지금까지 시도한 것이 무엇인지, 그리고 작동하지 않는 것이 무엇인지 명확히하십시오. –
arrayData에서 데이터를 가져오고 indexPath를 사용하여 데이터를 직렬로 가져옵니다. 그래서 cellForRowAtIndexPath가 이전에 시퀀스에서 호출되지 않았을 때 테이블에 임의의 데이터가 표시됩니다. – psijic