배열의 항목을 기반으로 tableview 셀을 표시하려고하지만 일부 이상한 이유로 배열의 첫 번째 항목 만 표시합니다. print 문을 사용할 때 올바르게 반복되는 배열을 보여줍니다.for 루프는 tableView에 표시하려고 할 때 배열의 첫 번째 항목 만 표시합니다.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = restaurantTableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath) as! restaurantCell
for rest in restaurants {
cell.restaurantImageView.image = UIImage(named: rest)
cell.restaurantNameLabel.text = rest
}
return cell
}
잘못 쓰고 있습니다. 단일 셀에 몇 개의 이미지보기가 있습니까? –
'cellForRowAt'에'for' 루프를 사용하지 않습니다. 이 함수는 행당 한 번 호출됩니다. 'indexPath.row'를 사용하여 배열의 오른쪽 요소에 접근하십시오. – Paulw11