ios,怎么做打开一个界面,里面的textfield自动打开键盘,提示你输入?

ios,怎么做打开一个界面,里面的textfield自动打开键盘,提示你输入?,第1张

将textfield设成属性就是在.h文件中写@property。。。

解决这个同时加上代理,然后在.m文件中给textfield设置代理

self.textfield.delegate=self

再用一个代段弊顷理方法

-(void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated]// 1

[self.textField becomeFirstResponder]/握陆/ 2

}

1是调用父卜橘类代理方法,2是将textfield设成第一响应者,就OK了

运行以下代码试试看。

public static void main(String[] args) {

Frame frame = new Frame("打开文件窗口")

frame.setLayout(new FlowLayout(FlowLayout.CENTER))

frame.setBounds(100, 200, 400, 300)

frame.addWindowListener(new WindowAdapter() {

@Override

public void windowClosing(WindowEvent e) {

System.exit(0)

}

})

final TextField txtField = new TextField(50)

Button button = new Button("册笑打开指定文稿姿滑件")

button.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

String path = txtField.getText()

System.out.println(path)

if (path.length() == 0) {

return

}

try {

Runtime.getRuntime().exec("explorer.exe /键腊n, " + path)

} catch (IOException ex) {

ex.printStackTrace()

}

}

})

frame.add(txtField)

frame.add(button)

frame.setVisible(true)

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12417920.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存