我的应用有一个ViewController,包含多个文本字段和自定义UI元素,排列为带有“提交”和“重置”按钮的表单。
我想在用户点击提交按钮时重置所有文本字段和自定义UI元素,以便用户感觉再次打开相同的表单。
我尝试在点击“提交”按钮时调用ViewDidLoad()和setNeedsDisplay(),但之前由用户填充的数据保持不变。
请帮助!
答案 0 :(得分:1)
只需将所有文本字段的文本设置为空字符串(text
值)即可。没有神奇的功能来清理视图中的所有内容。
唯一的另一个解决方案是再次实际显示ViewController,但这可能不是你想要的,因为它会导致开销,你可能会在屏幕上看到一些切换。
答案 1 :(得分:-1)
如果您以编程方式对文本字段和其他对象进行编码,则可以通过在预定义方法中添加所有UI代码来每次刷新viewController: - (void)viewWillAppear:(BOOL)animated {}并且您应该删除所有自我.view元素通过添加此代码。 [self.view.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
viewWillAppear中的代码将如下所示。
Traceback (most recent call last): File "/Users/root/test/foo.py", line 2, in <module> import socketio File "/Users/root/test/venv/lib/python3.6/site-packages/socketio/__init__.py", line 8, in <module> from .zmq_manager import ZmqManager File "/Users/root/test/venv/lib/python3.6/site-packages/socketio/zmq_manager.py", line 5, in <module> import eventlet.green.zmq as zmq File "/Users/root/test/venv/lib/python3.6/site-packages/eventlet/__init__.py", line 10, in <module> from eventlet import convenience File "/Users/root/test/venv/lib/python3.6/site-packages/eventlet/convenience.py", line 6, in <module> from eventlet.green import socket File "/Users/root/test/venv/lib/python3.6/site-packages/eventlet/green/socket.py", line 21, in <module> from eventlet.support import greendns File "/Users/root/test/venv/lib/python3.6/site-packages/eventlet/support/greendns.py", line 390, in <module> resolver = ResolverProxy(hosts_resolver=HostsResolver()) File "/Users/root/test/venv/lib/python3.6/site-packages/eventlet/support/greendns.py", line 171, in __init__ self._load() File "/Users/root/test/venv/lib/python3.6/site-packages/eventlet/support/greendns.py", line 198, in _load lines = self._readlines() File "/Users/root/test/venv/lib/python3.6/site-packages/eventlet/support/greendns.py", line 184, in _readlines for line in fp: File "/Users/root/test/venv/bin/../lib/python3.6/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xe9 in position 33: ordinal not in range(128)