我想返回tableView中的不同單元格。通常在這種情況下,我會返回不同的單元格,然後在底部返回零,但在這種情況下,它會給我和錯誤。我試過也返回一個空單元格,但也給我和錯誤。不能返回單元格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 2015-09-20 01:42:07