2017-03-18 72 views
1

當我想在ViewController中創建一個UITableView。 我做了所有完全一樣的教程,但它在AppDelegate.swift中的class AppDelegate: UIResponder, UIApplicationDelegate {上收到了此錯誤「Thread one signal SIGABRT」。 我最近問過這個問題以前的所有代碼,但每個答案都說,他們需要更多的信息。線程1信號Xcode中的SIGABRT錯誤[Swift]

所以我已經使整個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 
    } 

} 

但我已經找到了故障:當我卸下出口TableVi ew - DataSource我沒有得到這個錯誤,但是我只在TableView中得到空單元格。

+0

該錯誤與'AppDelegate'無關。表格視圖出口很可能未在Interface Builder中連接。或者自定義表視圖單元格的類未設置爲自定義類。請記住:**任何感嘆號都可能導致崩潰**。 – vadian

+0

@vadian你可以查看視頻https://workupload.com/file/24NNW68(Passwort是「ThePassword」(沒有「」))並告訴我我做錯了什麼? – Korne127

+0

我告訴過你:Interface Builder中沒有連接其中一個插座。覈實。 – vadian

回答

0

我看過你的視頻。我認爲這個錯誤是一個小問題。您需要將您的自定義單元的重用標識符設置爲屬性檢查器中的「單元」。在此方法中正確使用它:

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中的單元格並選擇屬性檢查器。在「標識符」框中輸入「單元格」。

+0

超級,它的作品!非常感謝你! – Korne127