标签 - >警报控制器文本字段?我可以在警报控制器的文本字段中编辑标签中的预先存在的文本吗? Swift 3,Xcode 8,IOS

时间:2017-02-28 18:37:31

标签: ios swift3 label textfield uialertcontroller

基本上,i have an alert controller set up so that when i click a button in the view controller, an alert controller pops up and i can type words into a textfield, click an "OK" button并将该文本插入视图控制器的标签中。我已经扩展了这个能力,所以我可以preset keywords (like "Good," "Likely" and "Almost") that i can select from in the alert controller to speed up the typing process, as these words are typed a lot in my app.我想知道你是否也可以编辑我选择的那些关键词?每当我尝试将文本添加到标签中的任何文本时,我都必须从空白文本字段开始。

具体来说,无论我的标签中是否有任何文字,我可以在文本字段中准备好该文本进行编辑,下次我拉出警报控制器吗?

这是我到目前为止的第二张图片:

//Editable Text Box with Preset Keywords

@IBOutlet weak var UselessLabel: UILabel!

@IBAction func UselessTapped(_ sender: UIButton) {
    print("Useless Button Tapped")
    openUselessAlert()

}

func openUselessAlert() {

    //Create Alert Controller
    let alert9 = UIAlertController (title: "Uselss:", message: nil, preferredStyle: UIAlertControllerStyle.alert)

    //preset keyword as button in alert controller
    let bt1 = UIAlertAction(title: "Good", style: UIAlertActionStyle.default){
        (action) in self.UselessLabel.text = "Good"}

    alert9.addAction(bt1)

    //preset keyword as button in alert controller
    let bt2 = UIAlertAction(title: "Likely", style: UIAlertActionStyle.default){
        (action) in self.UselessLabel.text = "Likely"}

    alert9.addAction(bt2)

    //preset keyword as button in alert controller
    let bt3 = UIAlertAction(title: "Almost", style: UIAlertActionStyle.default){
        (action) in self.UselessLabel.text = "Almost"}

    alert9.addAction(bt3)

    //Create Cancel Action
    let cancel9 = UIAlertAction(title: "CANCEL", style: UIAlertActionStyle.cancel, handler: nil)

    alert9.addAction(cancel9)


    //Create OK Action
    let ok9 = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) { (action: UIAlertAction) in print("OK")
        let textfield = alert9.textFields?[0]
        print(textfield?.text!)
        self.UselessLabel.text = textfield?.text!
    }

    alert9.addAction(ok9)

    //Add Text Field
    alert9.addTextField { (textfield: UITextField) in
        textfield.placeholder = "Useless"
    }

    //Present Alert Controller
    self.present(alert9, animated:true, completion: nil)
}

请帮忙!我对Xcode和一般的编程都很陌生,所以当谈到这一点时,我是一个很大的白痴。

谢谢:)

1 个答案:

答案 0 :(得分:0)

只需用文字替换占位符

java.net.ConnectException: Connexion terminée par expiration du délai d'attente (Connection timed out)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1138)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1022)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1020)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivilegedWithCombiner(AccessController.java:782)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1019)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1316)
at sun.net.www.protocol.http.HttpURLConnection.access$100(HttpURLConnection.java:91)
at sun.net.www.protocol.http.HttpURLConnection$8.run(HttpURLConnection.java:1283)
at sun.net.www.protocol.http.HttpURLConnection$8.run(HttpURLConnection.java:1281)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessController.doPrivilegedWithCombiner(AccessController.java:782)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1280)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:250)
at com.codename1.build.client.BuildProcess.uploadToS3(BuildProcess.java:305)
at com.codename1.build.client.BuildProcess.sendS3Build(BuildProcess.java:366)
at com.codename1.build.client.BuildProcess.sendRequestToServer(BuildProcess.java:432)
at com.codename1.build.client.CodeNameOneBuildTask.execute(CodeNameOneBuildTask.java:507)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
at sun.reflect.GeneratedMethodAccessor92.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.Target.performTasks(Target.java:456)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:286)
at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:555)
at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153)

/home/path/to/myProject/build.xml:338: Error in server build process
BUILD FAILED (total time: 2 minutes 15 seconds)