2017-01-01 1 views
2

オンラインSwiftコースに従っており、テーブルビューを作成しています。チュートリアルのすべてのコードは、いくつかの調整だけでほとんどコピーされました(コースは古いバージョンのスピーディで教えられていますが、私はスイフト3を使用しています)。チュートリアルによると、名前が表示された4行のテーブルビューを取得する必要がありますが、私が得たものは "シグナルSIGABRT"エラーです。そして、エラーは特に指摘されていませんでした。アウトレット「データソース」と「デリゲート」を接続した後に「スレッド1:信号SIGABRT」エラーが発生する

ここで何が間違っていますか?私が "データソース"コンセントに接続しなかった場合、私は問題なくシミュレータを実行できますが、名前は表示されません。しかし、私が接続を行うと、シミュレータを実行することすらできません。私は本当に私が質問を明確かつ読者にやさしいものにしてくれることを願っています!

import UIKit 

class ViewController: UIViewController, UITableViewDelegate{ 

var cellContent = ["xiaohong","xiaohua", "xiaogang" ,"xiaoxiao"] 

public override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 
} 
public func tableView(_tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return cellContent.count 
} 
public func tableView(_tableView: UITableView, cellForRowAtindexPath indexPath:NSIndexPath) -> UITableViewCell { 
    let cell = UITableViewCell(style: UITableViewCellStyle.default,reuseIdentifier:"Cell") 
    cell.textLabel?.text = cellContent[indexPath.row] 
    return cell } 
override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 
} 

私はここでエラーメッセージ全体を貼り付けたいと思います!

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:. 
} 
} 

ありがとうございます!

+0

プロジェクトのZIPファイルを作成し、それをWeTransferやそのようなサービスでホストできるのであれば、あなたを助けてくれる方が簡単だと思います。 –

+0

今Wetransferにあり、リンクはhttps://wetransfer.com/downloads/b7321f3dadcd688228715bba053d159920170101114400/4a12c5 – Frostless

答えて

0

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

tableView(_ tableView: UITableView, numberOfRows...で必要とされるアンダースコアの後にスペース文字が表示されます。

さらにあなたがInterface Builderで

let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) 
+0

ありがとうございます! :) – Frostless

1

私が考えることができる唯一の問題です。あなたのtableviewメソッドのヘッダーがデータソースのメソッドヘッダーと一致しないか:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    <#code#> 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    <#code#> 
} 

cellForRowメソッドの問題。これはDataSourceメソッドと一致しません。スイフト3方法cellForRowAtindexPathの署名で

+0

ありがとうございました:) – Frostless

0

を設計し、再利用可能な細胞を使用することになっている私は、あなたがWeTransferに掲載し、いくつかの問題があったプロジェクトをチェックします。

まず、hasan83が述べたように、メソッドのシグネチャは間違っています。そのため、UITableViewDataSourceのメソッドが見つかりません。これはクラッシュを引き起こします。 Xcodeでオートコンプリート機能を使用することをお勧めします。これにより、自動的に正しいメソッドシグネチャが取得されます。 tableViewと入力して、tableViewデータソースとデリゲートメソッドのリストを取得してください(現在のクラスにこれらのプロトコルが追加されている場合)。

また、ヘッダーなどから属性@available(iOS 2.0, *)をコピーしたようですが、このコードはプロパティとして表示されるので削除する必要があります。

固定プロジェクトはhereです。

+0

あなたのお手伝いをしてくれてありがとう!それを感謝する – Frostless

関連する問題