'NSRangeException',原因:'*** -[__NSArrayM objectAtIndex:]:索引 43 超出范围 [0 .. 39]'
在下面的代码中,为什么总是else
执行该块,而在其中使用相同的代码CellForRowAtIndexPath
却可以正常工作?
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if let tableItem = dataArray[indexPath.row] as? GADNativeExpressAdView {
valueToPass = indexPath.row
self.performSegueWithIdentifier("showDetails", sender: self)
} else {
valueToPass = indexPath.row
self.performSegueWithIdentifier("showDetails", sender: self)
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let nativeExpressAdView = dataArray[indexPath.row] as? GADNativeExpressAdView {
let reusableAdCell = tableView.dequeueReusableCellWithIdentifier("NativeExpressAdViewCell", forIndexPath: indexPath)
// Remove previous GADNativeExpressAdView from the content view before adding a new one.
for subview in reusableAdCell.contentView.subviews {
subview.removeFromSuperview()
}
reusableAdCell.contentView.addSubview(nativeExpressAdView)
// Center GADNativeExpressAdView in the table cell's content view.
nativeExpressAdView.center = reusableAdCell.contentView.center
return reusableAdCell
}
else {
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as? ProductCell
dataDict = dataArray[indexPath.row] as! NSMutableDictionary
cell!.productName?.text = dataDict.objectForKey("name") as? String
let member : NSString
member = (dataDict.objectForKey("Member") as? String)!
cell!.productMemberName?.text = "Member: " + (member as String)
cell!.productFavorite?.setBackgroundImage(UIImage(named: ""), forState: UIControlState.Normal)
cell!.productImage?.image = UIImage(named: (dataDict.objectForKey("name") as? String)! + ".jpg")
let imageName = "cellArrow"
let image = UIImage(named: imageName)
let imageView = UIImageView(image: image!)
cell?.accessoryView = imageView
return cell!
}
}
知道我应该改变什么didSelectRowAtIndexPath()
吗?