0
我試圖使自定義表格視圖單元格時,我按我的應用程序的註釋顯示按鈕的位置。當我按下按鈕時,會出現一個空單元格,我無法找出它出了什麼問題。你有什麼建議? 由於事先自定義表格單元格不顯示任何內容 - 斯威夫特2
類的ViewController:UIViewController中, MKMapViewDelegate,CLLocationManagerDelegate,UIPopoverPresentationControllerDelegate,UITableViewDataSource,的UITableViewDelegate {
struct MyData {
var imagy:UIImage
var title:String
var details:String
}
var tableData: [MyData] = []
@IBOutlet weak var mapView: MKMapView!
let locationManager = CLLocationManager()
var mapItemData:MKMapItem!
let textCellIdentifier = "TextCell"
//TableViewDataSource functions
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableData.count
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int{ return 1 }
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
// Create a new cell with the reuse identifier of our prototype cell
// as our custom table cell class
let cell = tableView.dequeueReusableCellWithIdentifier("TableViewCell") as! TableViewController
// Set the first row text label to the firstRowLabel data in our current array item
cell.imagy.image = tableData[indexPath.row].imagy
// Set the second row text label to the secondRowLabel data in our current array item
cell.title.text = tableData[indexPath.row].title
// Set the second row text label to the secondRowLabel data in our current array item
cell.details.text = tableData[indexPath.row].details
// Return our new cell for display
tableView.delegate = self
tableView.dataSource = self
return cell
}
override func prepareForSegue(segue: UIStoryboardSegue,
sender: AnyObject?){
// Set any data to be shown on the table view here
}
var picture:[UIImage] = [
UIImage(named: "pic1.jpg")!,
//UIImage(named: "pic2.jpg")!,
//UIImage(named: "pic3.jpg")!,
//UIImage(named: "pic4.jpg")!,
// UIImage(named: "pic5.jpg")!,
// UIImage(named: "pic6.jpg")!,
//UIImage(named: "pic7.jpg")!,
UIImage(named: "pic8.jpg")!, ]
override func viewDidLoad() {
super.viewDidLoad()
這是的TableView類:
類TableViewController:UITableViewCell的{
@IBOutlet weak var imagy: UIImageView!
@IBOutlet weak var title: UILabel!
@IBOutlet weak var details: UILabel!
@IBOutlet weak var exit: UIButton!
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
}
}
感謝您的回覆。問題是,不過,當我把它們放在viewDidLoad中,我得到一個錯誤「曖昧使用的tableview numberofrowsinsection的」 –
你創建表視圖的正確'IBOutlet'? – kientux
說實話,我真的不知道該怎麼做...... –