线程1信号XAB中的SIGABRT错误[Swift]

时间:2017-03-18 14:30:41

标签: swift xcode uitableview

当我想在ViewController中创建一个UITableView时。 我完全按照它的工作原理完成了所有工作,但我得到了这个错误"线程一信号SIGABRT"在AppDelegate.swift中的class AppDelegate: UIResponder, UIApplicationDelegate {上。 我之前用所有代码问过这个问题,但每个答案都说,他们需要更多的信息。

所以我把整个Xcode项目变成了新的,我用Screenium拍摄了它。 这是视频(10分钟; 53兆字节)https://workupload.com/file/24NNW68。 您必须输入密码

ThePassword

然后是" video.mov"的信息。点击下面的(蓝色)下载,abowe就是广告。

对于那些不想看视频的人(我14岁时就已经成功了,所以我的声音有点高:这是完整的代码:

AppDelegate.swift:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}

ViewController.swift

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var tableView: UITableView!
    var Label1multi = ["TableView","Alarm Clock","Green","Book"]
    var Label2multi = ["Pen", "1 Euro","Red","Mobile Phone"]
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 4
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! THISTableViewCell
        cell.Label1.text = Label1multi[indexPath.row]
        cell.Label2.text = Label2multi[indexPath.row]
        return cell
    }

}

THISTableViewCell.swift:

import UIKit

class THISTableViewCell: UITableViewCell {

    @IBOutlet weak var Label1: UILabel!
    @IBOutlet weak var Label2: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

但我发现了失败:当我删除The Outlet TableView - DataSource时,我没有收到错误,但我只在TableView中获得空单元格。

1 个答案:

答案 0 :(得分:1)

我看了你的视频。我认为这个错误很小。您需要将自定义单元格的重用标识符设置为" cell"在属性检查器中。您可以在此方法中正确使用它:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = self.tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! THISTableViewCell
    cell.Label1.text = Label1multi[indexPath.row]
    cell.Label2.text = Label2multi[indexPath.row]
    return cell
}

在main.storyboard中选择单元格,然后选择属性检查器。输入" cell"在"标识符"框。

相关问题