UITextView不显示文本

时间:2016-07-17 17:08:48

标签: ios swift swift2 uitextview

我创建了一个UITextView课程,并且我在触摸时添加了UITextViewUITextView出现,但设置文字没有出现,当我触摸UITextView时,键盘会出现,但是当我开始写文字时,它不会出现。

这是我的UITextView课程:

import UIKit

class TextAnnotation: UITextView {

    override init(frame: CGRect, textContainer: NSTextContainer?) {
        super.init(frame: frame, textContainer: textContainer)
        self.text = "Text Field"
        self.textColor = UIColor.blackColor()
        self.userInteractionEnabled = true
        self.editable = true
        self.frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: 200, height: 50)
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

以下是我如何调用此类来触摸添加UITextView:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

    let textCenter = touches.first!.locationInView(view)
    let textView = TextAnnotation(frame: CGRect(x: textCenter.x, y: textCenter.y, width: 200, height: 50), textContainer: NSTextContainer())

    self.view.addSubview(textView)
}

如何显示设置文本以及开始输入时未显示原因

1 个答案:

答案 0 :(得分:1)

好的,mfxboot <- function(modform,dist,data,boot=1000,digits=3){ x <- glm(modform, family=binomial(link=dist),data) # get marginal effects pdf <- ifelse(dist=="probit", mean(dnorm(predict(x, type = "link"))), mean(dlogis(predict(x, type = "link")))) marginal.effects <- pdf*coef(x) # start bootstrap bootvals <- matrix(rep(NA,boot*length(coef(x))), nrow=boot) set.seed(1111) for(i in 1:boot){ samp1 <- data[sample(1:dim(data)[1],replace=T,dim(data)[1]),] x1 <- glm(modform, family=binomial(link=dist),samp1) pdf1 <- ifelse(dist=="probit", mean(dnorm(predict(x, type = "link"))), mean(dlogis(predict(x, type = "link")))) bootvals[i,] <- pdf1*coef(x1) } res <- cbind(marginal.effects,apply(bootvals,2,sd),marginal.effects/apply(bootvals,2,sd)) if(names(x$coefficients[1])=="(Intercept)"){ res1 <- res[2:nrow(res),] res2 <- matrix(as.numeric(sprintf(paste("%.",paste(digits,"f",sep=""),sep=""),res1)),nrow=dim(res1)[1]) rownames(res2) <- rownames(res1) } else { res2 <- matrix(as.numeric(sprintf(paste("%.",paste(digits,"f",sep=""),sep="")),nrow=dim(res)[1])) rownames(res2) <- rownames(res) } colnames(res2) <- c("marginal.effect","standard.error","z.ratio") return(res2) } 函数 - 初始化并将子视图添加到superview是一个不好的地方,因为它可以多次调用。
我想你有超过1个touchesBegan实例,并且每个新实例都覆盖了前一个实例。

我可以建议 - 将textView初始化和布局代码替换为textViewinit等功能,隐藏您的viewDidLoad和触摸事件 - 只需展示下。