SIGABRTと表示される
https://akira-watson.com/iphone/tableview_3.html
上記のサイトにあるコードを写経しているのですが、実行すると
let subVC: SubViewController = (segue.destinationViewController as? SubViewController)!
の部分が SIGABRTと表示されます。
SIGABRTとはコードを入力する順番が違う、某サイトで見たのですが、今回もそういうことなのでしょうか。。。
import UIKit
class ViewController: UIViewController , UITableViewDataSource, UITableViewDelegate{
@IBOutlet var table:UITableView!
let imgArray: NSArray = ["img0.png", "img1.png", "img2.png", "img3.png"]
let label2Array: NSArray = ["あ", "い", "え", "う"]
var selectedImage: UIImage?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return imgArray.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = table.dequeueReusableCellWithIdentifier("tableCell", forIndexPath: indexPath)
let img = UIImage(named: "\(imgArray[indexPath.row])")
let imageView = table.viewWithTag(1) as! UIImageView
imageView.image = img
let label1 = table.viewWithTag(2) as! UILabel
label1.text = "No.\(indexPath.row + 1)"
let label2 = table.viewWithTag(3) as! UILabel
label2.text = "\(label2Array[indexPath.row])"
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectedImage = UIImage(named:"\(imgArray[indexPath.row])")
if selectedImage != nil {
performSegueWithIdentifier("toSubViewController", sender: nil)
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
if (segue.identifier == "toSubViewController") {
let subVC: SubViewController = (segue.destinationViewController as? SubViewController)!
subVC.selectedImg = selectedImage
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}