我有一个正确设置的表视图,但没有显示任何内容。填充数组并正确设置所有委托。我该如何解决?
override func viewDidLoad() {
super.viewDidLoad()
self.friendstable.rowHeight = 150.0
friendstable.allowsSelection = false
self.friendstable.dataSource = self
self.friendstable.delegate = self
self.friendstable.registerClass(UITableViewCell.self, forCellReuseIdentifier: "friendcell")
// Do any additional setup after loading the view.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return titleofsong.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
//var cell = friendstable.dequeueReusableCellWithIdentifier("friendcell", forIndexPath: indexPath)
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "friendcell")
cell.textLabel?.text = titleofsong[indexPath.row]
cell.detailTextLabel?.text = artist[indexPath.row]
cell.textLabel?.font = UIFont(name: "Lombok", size: 22)
cell.textLabel?.textColor = UIColorFromRGB("4A90E2")
cell.detailTextLabel?.font = UIFont(name: "Lombok", size: 16)
cell.detailTextLabel?.textColor = UIColor.blackColor()
cell.textLabel?.numberOfLines = 0;
cell.textLabel?.lineBreakMode = NSLineBreakMode.ByWordWrapping
cell.backgroundColor = UIColor.clearColor()
return cell
}
答案 0 :(得分:-1)
func GetRandomObjectID(){
ObjectIDs = ["objectid1","objectid2","objectid3","objectid4","objectid5","objectid6","objectid7"]
RandomID = Int(arc4random_uniform(UInt32(ObjectIDs.count)))
}
func CallData(){
GetRandomObjectID()
var query : PFQuery = PFQuery(className: "QuestionsandAnswers")
query.getObjectInBackgroundWithId(ObjectIDs[RandomID]){
(ObjectHolder : PFObject?, error: NSError?) -> Void in
if (error == nil) {
self.Question = ObjectHolder!.valueForKey("Question") as? String
self.Answers = ObjectHolder!.valueForKey("Answers") as? Array
self.Answer = ObjectHolder!.valueForKey("Answer") as? String
if(self.Answers.count > 0){
self.questionLabel.text = self.Question
self.Button1.setTitle(self.Answers[0], forState: UIControlState.Normal)
self.Button2.setTitle(self.Answers[1], forState: UIControlState.Normal)
self.Button3.setTitle(self.Answers[2], forState: UIControlState.Normal)
self.Button4.setTitle(self.Answers[3], forState: UIControlState.Normal)
}
} else {
NSLog("There is something wrong!")
}
}
}