xcode - iOS : 'MyViewController' does not conform to protocol 'UITableViewDataSource' -
i new
ios
swift
development. used work previousxcode 6 beta
.i have downloaded
xcode 6.0.1
, can not workxcode version: 6.0.1
i still getting "'
myviewcontroller
' not confirm protocol 'uitableviewdatasource
' " when try run example.
can please me? have gone through other issues on site , added required functions "uitableviewdatasource
";
import uikit import foundation class myviewcontroller: uiviewcontroller, uitableviewdelegate, uitableviewdatasource { var array1:[string] = ["one","two","three","four"] var array2:[string] = ["ios","android","java","c++","swift"] let sectioncount = 2 var mytableview:uitableview! // init(nibname nibnameornil: string?, bundle nibbundleornil: nsbundle?) { // var rect = cgrectmake(0, 0, 220, 320) // mytableview = uitableview(frame: rect, style: uitableviewstyle.grouped) // super.init(nibname: nil, bundle: nil) // // custom initialization // } override func viewdidload() { super.viewdidload() var rect = cgrectmake(0, 0, 320, 600) mytableview = uitableview(frame: rect, style: uitableviewstyle.grouped) mytableview!.delegate = self mytableview!.datasource = self self.view.addsubview(mytableview) } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } //datasourrce //tableview:tableview,section: func tableview(tableview: uitableview!, numberofrowsinsection section: int) -> int{ switch section{ case 0: return array1.count case 1: return array2.count default: return 1 } } func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { //func tableview(tableview: uitableview!, cellforrowatindexpath indexpath: nsindexpath!) -> uitableviewcell!{ //---cellstart---- let identifier = "identifier" // var cell:uitableviewcell //cell var cell = tableview.dequeuereusablecellwithidentifier(identifier) as? mycell if cell == nil { // cell = uitableviewcell(style: uitableviewcellstyle.subtitle, reuseidentifier: identifier) cell = mycell(style: uitableviewcellstyle.subtitle, reuseidentifier: identifier) } //---cellend---- switch indexpath.section{ case 0: // cell!.textlabel.text = array1[indexpath.row] cell!.mylable!.text = array1[indexpath.row] case 1: // cell!.textlabel.text = array2[indexpath.row] cell!.mylable!.text = array2[indexpath.row] default: println() } var image = uiimage(named: "images/qq.png") // cell!.imageview.image = image cell!.myimageview!.image = image // cell!.detailtextlabel.text = "\(indexpath.section)\(indexpath.row) return cell! } //datasourrce func numberofsectionsintableview(tableview: uitableview!) -> int { return sectioncount } func tableview(tableview: uitableview, titleforheaderinsection section: int) -> string? { var title:string? = nil switch section { case 0: title = "num" case 1: title = "prog" default: title = nil } return title } func tableview(tableview: uitableview, diddeselectrowatindexpath indexpath: nsindexpath) { println("test\(indexpath.section) \(indexpath.row)") } func tableview(tableview: uitableview, heightforrowatindexpath indexpath: nsindexpath) -> cgfloat { return 60.0 } func numberofcomponentsinpickerview(pickerview: uipickerview!) -> int {} func pickerview(pickerview: uipickerview!,numberofrowsincomponent component: int) -> int{} func pageviewcontroller(pageviewcontroller: uipageviewcontroller, viewcontrollerbeforeviewcontroller viewcontroller: uiviewcontroller) -> uiviewcontroller?{ } func pageviewcontroller(pageviewcontroller: uipageviewcontroller, viewcontrollerafterviewcontroller viewcontroller: uiviewcontroller) -> uiviewcontroller?{ } }
***************** cell class ***********************************
import foundation import uikit class mycell: uitableviewcell { let indetifier:string = "indetifier" var mylable:uilabel? var myimageview:uiimageview? override init(style: uitableviewcellstyle, reuseidentifier: string!) { super.init(style: .subtitle, reuseidentifier: indetifier) var rect = cgrectmake(10, 0, 60, 30) self.mylable = uilabel() self.mylable!.frame = rect self.mylable!.textcolor = uicolor.redcolor() self.contentview.addsubview(self.mylable!) var imagerect = cgrectmake(160, 10, 40, 40) self.myimageview = uiimageview() self.myimageview!.frame = imagerect self.contentview.addsubview(self.myimageview!) } required init(coder adecoder: nscoder) { fatalerror("init(coder:) has not been implemented") } }
you need @ whole error message. specific message includes additional information methods missing:
type 'myviewcontroller' not conform protocol 'uitableviewdatasource' protocol requires function 'tableview(_:numberofrowsinsection:)' type '(uitableview, numberofrowsinsection: int) -> int' candidate has non-matching type '(uitableview!, numberofrowsinsection: int) -> int'
so... numberofrowsinsection takes optional uitableview, , should take required uitableview (this change made between 6 , 6.1, uitableview delegate , datasource methods take required tableview , indexpath values)
Comments
Post a Comment