ios - UIAlertController 给出错误
<p><p>我是 IOS 新手。我有一个示例项目并尝试在此基础上学习 Obj-C。</p>
<p>现在我正在学习如何使用 UIAlertController。
我有这样的代码:</p>
<pre><code>if (loanAmount == 0) {
UIAlertController *ErrorMessage =;
} else
{ // sets labels
self.interestLabel.text = ;
self.periodLabel.text = ;
self.totalLabel.text = ;
</code></pre>
<p>================================================ ==========================</p>
<p>但是当我运行模拟器时。模拟器上应该有弹出消息。取而代之的是一个错误:</p>
<pre><code>015-10-11 13:56:39.985 iBank Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController: 0x7ca82400>)
</code></pre>
<p>任何帮助将不胜感激</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>试试这个</p>
<pre><code>if (loanAmount == 0) {
UIAlertController * ErrorMessage = [UIAlertController
alertControllerWithTitle:@"Invalid amount"
message:@"Enter a valid number"
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action")
style:UIAlertActionStyleCancel
handler:^(UIAlertAction *action)
{
NSLog(@"Cancel action");
}];
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(@"OK action");
}];
;
;
;
}
else
{
self.interestLabel.text = ;
self.periodLabel.text = ;
self.totalLabel.text = ;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - UIAlertController 给出错误,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/33064696/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/33064696/
</a>
</p>
页:
[1]