2016-04-02 11 views
0

スライダとUITableViewを使用してタイムテーブルアプリケーションを作成しようとしていますが、SIGABRTエラーが発生します。私はすべてのアウトレットとアクションを再リンクするだけでなく、最初からやり直そうとしましたが、それでも動作しないようです。SIGABRTエラーを解決できません - UITableViewを使用したタイムテーブルアプリケーション

が、私はここに正しくフォーマットでそれを貼り付けることはできませんので、私はpastebin.comの上に置く

デバッグコード:http://pastebin.com/cBaALXWq

ViewController.swift

import UIKit 

class ViewController: UIViewController, UITableViewDelegate { 

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. 
} 
@IBOutlet weak var sliderValue: UISlider! 
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return 50 
} 
@IBAction func sliderMoved(sender: AnyObject) { 
    var timesTableIndex: Int = Int(sender.value)! 
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell") 
     cell.textLabel?.text = String(timesTableIndex*indexPath.row+1) 
     return cell 
    } 
} 

} 

AppDelegate.swift。あなたは@IBActionメソッド内cellForRowAtIndex:を追加しましたように私に見えるライン4

import UIKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

EDIT

@IBOutlet weak var sliderValue: UISlider! 
var timesTableIndex: Int? 
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return 50 
} 
@IBAction func sliderMoved(sender: AnyObject) { 
    timesTableIndex = Int(sliderValue.value * 50) 
    } 
} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell") 
cell.textLabel.text = String(timesTableIndex*(1+indexPath.row)) 
return cell 

} 
+0

更新後も同じ問題が発生していますか?ストーリーボードでUITableviewを作成しましたか?私はIBOutletまたはプログラムでテーブルビュー – HardikDG

答えて

0

にエラーが発生します。あなたがする必要があるのは、メソッドから取り除くことです。さらにsliderMoved:メソッドを呼び出すとcellForRowAtIndexPath:にアクセスできるようにtimesTableIndex変数をグローバルに設定する必要があり、メソッドをtableViewと呼びます。

var timesTableIndex: Int = 0 // Now global variable 

@IBAction func sliderMoved(sender: AnyObject) { 
    timesTableIndex = Int(sender.value)! 
    self.tableView.reloadData() 
} 

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) 
    cell.textLabel?.text = "\(timeTableIndex * indexPath.row + 1)" 
    return cell 
} 

また、あなたがあなたのテーブルビューにdequeueReusableCellWithIdentifier方法を使用していないようですので、私はそれを使用するコードを更新しました。ストーリーボードにCell再利用識別子を設定する必要はありません。

+0

の実装を見つけられなかったので、あなたの答えに感謝します。しかし今、それはfunc tableViewで、timesTableIndexが何であるかを知らないと言いますが、私はそれをグローバルに宣言しました。 – kevini15

+0

コントローラクラスでグローバルに定義されていますか?また、次の構文を使用する必要があります。 'cell.textLabel.text =" \(timeTableIndex * indexPath.row + 1) "' –

+0

はい、確信しています。私はそれを元の投稿に入れました。さて、ありがとう! – kevini15

0

あなたがクラスを登録することができ、他のストーリーボードで「セル」としてCellReuseIdentifierを設定するストーリーボードにあなたのセルを作成している場合は、ストーリーボード

@IBOutlet weak var sliderValue: UISlider! 
@IBOutlet weak var tableview: UITableView! 
var timesTableIndex: Int = 0 

@IBAction func sliderMoved(sender: AnyObject) { 
     timesTableIndex = Int(sliderValue.value * 50) 
     tableview.reloadData() 
    } 

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

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

      let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) 
     cell.textLabel!.text = String(1*(1+indexPath.row)) 
     return cell 
} 

でテーブルビューを作成した場合、これはあなたのテーブルビューのコードでなければなりません以下のような

override func viewDidLoad() { 
    super.viewDidLoad() 
    //tableView is IBOutlet instance of UITableview 
    tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "test") 
} 

にまた、あなたが私はストーリーボードテーブルビューオブジェクトに

0

をテーブルビューのデリゲート/データソースを設定している確認してください問題を解決することができました。私は誤ってプロトタイプのセルをViewControllerクラスの外に設定する関数を置いて、すべてを説明しています。助けてくれてありがとう!

関連する問題