tableView에서 다른 셀을 반환하려고합니다. 일반적으로이 경우 다른 셀을 반환하고 아래쪽에 nil을 반환하지만이 경우에는 오류가 발생합니다. 나는 빈 셀을 반환하려고했지만, 또한 나에게 오류를 준다. 내가cellForRowAtIndexPath에서 셀을 반환 할 수 없습니다.
return nil
및
var cell: UITableViewCell!
return cell
을 시도했지만 모두 오류를 반환했습니다 무엇
. 이 문제를 어떻게 해결할 수 있습니까?
cellForRowAtIndex에만 선언하는
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.row == 0 {
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("imageCell", forIndexPath: indexPath) as UITableViewCell
var imageFile = cell.viewWithTag(100) as PFImageView
imageFile.image = itemFile
cell.selectionStyle = UITableViewCellSelectionStyle.None
return cell
} else if indexPath.row == 1 {
let cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier("segmentCell", forIndexPath: indexPath) as UITableViewCell
var titleLabel = cell.viewWithTag(101) as UILabel?
titleLabel?.text = itemTitle
let segmentControl = cell.viewWithTag(102) as UISegmentedControl
segmentControl.selectedSegmentIndex = segment
segmentControl.setTitle("Beskrivelse", forSegmentAtIndex: 0)
segmentControl.setTitle("Sælger", forSegmentAtIndex: 1)
segmentControl.setTitle("Lokation", forSegmentAtIndex: 2)
segmentControl.tintColor = UIColor(rgba: "#619e00")
var font = UIFont(name: "Lato-Regular", size: 11)
var attributes:NSDictionary = NSDictionary(object: font , forKey: NSFontAttributeName)
segmentControl.setTitleTextAttributes(attributes, forState: UIControlState.Normal)
segmentControl.addTarget(self, action: "segmentAction:", forControlEvents: .ValueChanged)
cell.selectionStyle = UITableViewCellSelectionStyle.None
return cell
} else if indexPath.row == 2 {
switch segment {
case 0:
let cell = tableView.dequeueReusableCellWithIdentifier("CellZero", forIndexPath: indexPath) as DescViewCell
return cell
case 1:
let cell = tableView.dequeueReusableCellWithIdentifier("CellOne", forIndexPath: indexPath) as SellerViewCell
return cell
case 2:
let cell = tableView.dequeueReusableCellWithIdentifier("CellTwo", forIndexPath: indexPath) as LocationViewCell
return cell
default:
break
}
}
var cell: UITableViewCell!
return cell
}
'default : // case (2, 2)'비트는 우아하지 않다. 아마도 'fallthrough'를 사용했을 것입니까? 하지만 나는 그걸 정말로 좋아하지도 않는다. – pkamb