【发布时间】:2020-05-15 04:16:48
【问题描述】:
我正在 Swift Playgrounds for iPad 中编写一个模拟消息应用程序。每次我运行 Playground 时,都会收到错误消息“运行此页面时出现问题。检查您的代码是否存在问题。如果您卡住了,请删除此页面上的所有内容,然后重试”。这是我到目前为止所拥有的。这很简单,我不确定我做错了什么。
import UIKit
import PlaygroundSupport
class ChatView : UICollectionViewController, UICollectionViewDelegateFlowLayout {
override func viewDidLoad(){
super.viewDidLoad()
collectionView.register(ChatLogMessageCell.self, forCellWithReuseIdentifier: "cellId")
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: IndexPath) -> UICollectionViewCell{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) as! ChatLogMessageCell
cell.messageTextView.text = "sample message text"
return cell
}
}
class ChatLogMessageCell : UICollectionViewCell {
let messageTextView : UITextView = {
let textView = UITextView()
//textView.font = UIFont.systemFont(ofSize: 36)
textView.text = "sample message"
return textView
}()
func setupViews(){
addSubview(messageTextView)
}
}
PlaygroundPage.current.liveView = ChatView()
【问题讨论】:
-
游乐场往往是越野车。您是否尝试过在普通项目中运行它?
-
您没有为 textview 设置任何约束?
-
不幸的是,这必须在操场上完成。这是 Apple WWDC 学生挑战赛的参赛作品,要求所有参赛作品都是 Playgrounds。