ios - 带有 UIToolbar 错误的 UIDatePicker
<p><p>我正在使用 UIDatePicker 并在单击 UITextField 时实现 UIToolBar。但是当我单击文本字段时,它会崩溃。我正在使用以下代码。</p>
<pre><code>datepicker = [ initWithFrame:CGRectZero];
;
;
UIToolbar *toolbar= [ initWithFrame:CGRectMake(0,0,self.view.frame.size.width,44)];
toolbar.barStyle = UIBarStyleDefault;
UIBarButtonItem *flexibleSpaceLeft = [ initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem* doneButton = [ initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(dismiss)];
];
;
textField.inputAccessoryView = toolbar;
textField.inputView = datepicker;
</code></pre>
<blockquote>
<p>Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'Please file a radar on
UIKit with this log if you see this assertion. selectorString =
setTitle:, exercisedImplementations = {
"setTitle:" = (
); }'</p>
</blockquote>
<p>提前致谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>将 <code>UITextField</code> 的 <code>inputAccessoryView</code> 设置为已经有 superview 的 View 会导致崩溃。 </p>
<p>所以,不要将工具栏添加为 <code>UIDatePicker</code> 的 subview 。删除</p>
<pre><code>;
</code></pre>
<p>然后设置</p>
<pre><code>textField.inputAccessoryView = toolbar;
</code></pre>
<p>工具栏将出现在数据选择器上方。</p></p>
<p style="font-size: 20px;">关于ios - 带有 UIToolbar 错误的 UIDatePicker,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/51696632/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/51696632/
</a>
</p>
页:
[1]