我的scrollview xamarin ios的结构

时间:2017-06-22 18:21:42

标签: ios xamarin

我有以下结构,我想在我的ios应用程序中放置一个scrollView,当我将Scrowview放在这个结构中时,我的数据全部消失。如何在我的scrollview工作的地方建立一个正确的结构?

var posts = [postStruct]()
var  downloadURL : String = ""


override func viewDidLoad() {
    super.viewDidLoad()


    let ref = Database.database().reference().child("Posts")

    ref.observeSingleEvent(of: .value, with: { snapshot in

        print(snapshot.childrenCount)

        for rest in snapshot.children.allObjects as! [DataSnapshot] {

            guard let value = rest.value as? Dictionary<String,Any> else { continue }

            guard let  title = value["Title"] as? String else { continue }
            guard let  downloadURL = value["Download URL"] as? String else { continue }
            guard let  author = value["Author"] as? String else { continue }
            guard let  date = value["Date"] as? String else { continue }
            guard let  article = value["Article"] as? String else { continue }


            let post = postStruct(title: title, author: author, date: date, article: article, downloadURL: downloadURL)

            self.posts.append(post)


        }

        self.posts = self.posts.reversed(); self.tableView.reloadData()

    })




}


override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    var thePostView = segue.destination as! ArticleViewController
    thePostView.titleString = title!
}




override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return posts.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell")

    let label1 = cell?.viewWithTag(1) as! UILabel
    label1.text = posts[indexPath.row].title


    let imageView = cell?.viewWithTag(2) as! UIImageView
    let post = self.posts[indexPath.row];
    imageView.sd_setImage(with: URL(string: post.downloadURL), placeholderImage: UIImage(named: "placeholder"))

 return cell!





}

1 个答案:

答案 0 :(得分:0)

ScrollView中有多个子项。那不行。 ScrollView只能有一个直接孩子