我是迅速使用UI的新手,我需要帮助我收到错误。问题是“类型'MotionView'的值没有成员'tiltOutput'”。我不知道要在我的代码中添加成员。
我已经尝试过制作新的变量。
var tiltOut = 0
struct MotionView: View {
@State private var labelText: String = "tiltOutput"
var motionManager = CMMotionManager()
var body: some View {
Text(self.labelText)
.onAppear {
self.startGyro()
}
}
func startGyro() {
motionManager.gyroUpdateInterval = 0.2
motionManager.startGyroUpdates(to: OperationQueue.current!) {
(data, Error) in
if let myData = data
{
if myData.rotationRate.y > 3
{
tiltOut = tiltOut + 1
self.tiltOutput.text = "\(tiltOut)"
}
错误是:
"Value of type 'MotionView' has no member 'tiltOutput'"
我在线上找到它
self.tiltOutput.text = "\(tiltOut)"
答案 0 :(得分:1)
该错误明确指出没有成员tiltOutput,正确的方法是更改labelText,如下所示:
代替:
var db: SQLiteDatabase? = null
var cursor: Cursor? = null
try {
db = getReadWriteDB()
val query = "Select * From Table"
cursor = db.rawQuery(query, null)
} catch (e: Exception) {
e.printStackTrace()
} finally {
if (cursor != null && !cursor.isClosed()) {
cursor.close()
}
if(db != null && db.isOpen()) {
db.close()
}
}
要做:
self.tiltOutput.text = "\(tiltOut)"