※エラー部分にコメントアウトを入れています
import UIKit
class ViewController: UIViewController , UITableViewDelegate, UITableViewDataSource{
private let myItems : NSArray = ["TEST1","TEST2","TEST3"] private var myTableView: UITableView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. let barHeight: CGFloat = UIApplication.sharedApplication().statusBarFrame.size.height let displayWidth: CGFloat = self.view.frame.width let displayHeight: CGFloat = self.view.frame.height myTableView = UITableView(frame: CGRect(x: 0, y: barHeight, width: displayWidth, height: displayHeight - barHeight)) myTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "MyCell") myTableView.dataSource = self myTableView.delegate = self self.view.addSubview(myTableView) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { print("Num: \(indexPath.row)") print("Value: \(myItems[indexPath.row])") } func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return myItems.count } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//ここより下からエラーが出ます
let cell = tableView.dequeueReusableCellWithIdentifier("MyCell", forIndexPath: indexPath)
//エラー内容→ Constant'cell' inferred to have type 'AnyObject',which may be unexpected
cell.textLabel!.text = "(myItems[indexPath.row])"//エラー内容→ 'UILabel?' does not have a member named 'text'
return cell//エラー内容→ Type'AnyObject' cannot be implicity downcast to 'UITableViewCell';did you mean to use 'as' to force downcast?
}
}
回答2件
あなたの回答
tips
プレビュー