私は迅速な開発に新しいです。私はコンセントを作成せずにラベルのテキストにアクセスしようとしています。ラベルを付けるようにタグを設定し、テキストを取得しようとしました。swift 3.0でコンセントを作成せずにラベルやテキストフィールドのテキストにアクセスできますか?
私はそれを行うことができない私はそれに成功したが、私はプログラムで次のViewControllerにそのテキストをナビゲートしたいのですが、このリンクに How Can I access the textfields in static TableViewcells without creating referencing outlet?
を言及しました。誰も私のためにそれを助けることができますか?
私はあなたのコードを試してみましたし、それが動作する次のコード
for view: UIView in self.view.subviews {
if (view is UILabel) {
let stortboard = UIStoryboard.init(name:"Main",bundle:nil)
let vc = stortboard.instantiateViewController(withIdentifier: "SecondViewControllerID") as? SecondViewController
let lbl: UILabel? = (view as? UILabel)
vc?.lblData = lbl?.text
print(lbl?.text ?? "not found")
//self.navigationController?.pushViewController(vc!, animated: true)
self.present(vc!, animated: true, completion: nil)
}
}
あなたのラベルにタグを設定し、viewWithTagを取得してみましょう let foundView = self.view.viewWithTag(yourtag number) UILabel { print(lbl?。text? "not found") } –
'SecondViewController'に変数' lblData'がありますか? –
@ShitalあなたはSecondViewControllerに1つの文字列変数を作成し、currentViewController "vc?.variableName = lbl?.text"に設定してから、それをSecondViewControllerに使用する必要があります。viewControllerを押した後 –