gpt4 book ai didi

ios - Swift - 从 DetailViewController 访问 UITextView

转载 作者:行者123 更新时间:2023-11-30 13:18:57 25 4
gpt4 key购买 nike

我最近一直在开发一个新应用程序,但我一直遇到这个奇怪的问题。每次我尝试在 viewdidload 之外访问我的 textviews.text 属性时,都会收到错误“实例成员 'detailDescriptionLabel'(我的 textview)不能在类型 'DetailViewController'(我所在的类)上使用”我真的很感谢您的帮助。谢谢。

出现错误的代码:

var updated: String = detailDescriptionLabel.text {
didSet {

if updated != oldValue {
textFieldDidChange()
}

}
}

整个类,控制表格上的单元格(以防万一):

var start : CGPoint?

var red : CGFloat = 0.0
var green : CGFloat = 0.0
var blue : CGFloat = 0.0


@IBAction func erase(sender: AnyObject) {
red = 1
green = 1
blue = 1
}

@IBAction func clear(sender: AnyObject) {
self.imageView.image = nil
}


@IBAction func blackPen(sender: AnyObject) {
red = 0
green = 0
blue = 0
}

@IBAction func redPen(sender: AnyObject) {
red = 1
green = 0
blue = 0
}

@IBAction func bluePen(sender: AnyObject) {
red = 0
green = 0
blue = 1
}

@IBOutlet weak var detailDescriptionLabel: UITextView!

@IBOutlet weak var imageView: UIImageView!

let notes = PFObject(className: "Notes")



var detailItem: AnyObject? {
didSet {
// Update the view.
self.configureView()
}
}

func configureView() {

}


override func viewDidLoad() {

super.viewDidLoad()


// Do any additional setup after loading the view, typically from a nib.
self.configureView()

}




var updated: String = detailDescriptionLabel.text {
didSet {
if updated != oldValue {
textFieldDidChange()
}

}
}


func textFieldDidChange() {
let query = PFQuery(className: "Notes")
query.getObjectInBackgroundWithId("Content") { (notes, error) -> Void in

notes!["Content"] = self.detailDescriptionLabel.text
print("Updated")


}
}


override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer<Void>) {
let newText = change![NSKeyValueChangeNewKey] as! String
print(newText)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


func draw(start : CGPoint, end: CGPoint) {
UIGraphicsBeginImageContext(self.imageView.frame.size)
let context = UIGraphicsGetCurrentContext()
imageView?.image?.drawInRect(CGRect(x: 0, y: 0, width: imageView.frame.width, height: imageView.frame.height))
CGContextSetLineWidth(context, 6)
CGContextBeginPath(context)
//Define starting point
CGContextMoveToPoint(context, start.x, start.y)
//Define end point
CGContextAddLineToPoint(context, end.x, end.y)
//Close the path between the starting and ending point (draw)
CGContextSetRGBStrokeColor(context, red, green, blue, 1)
CGContextStrokePath(context)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
imageView.image = newImage
}

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let Touch = touches.first as UITouch!
start = Touch.locationInView(self.imageView)
}

override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let Touch = touches.first as UITouch?
let end = Touch?.locationInView(self.imageView)
if let s = self.start {
draw(s, end: end!)
}
self.start = end
}

最佳答案

似乎不允许以这种方式设置成员变量...您需要实现 textViewDidChange 委托(delegate)方法

关于ios - Swift - 从 DetailViewController 访问 UITextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37950749/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com