我是 IOS 新手。我有一个示例项目并尝试在此基础上学习 Obj-C。
现在我正在学习如何使用 UIAlertController。
我有这样的代码:
if (loanAmount == 0) {
UIAlertController *ErrorMessage =[UIAlertController alertControllerWithTitle"Invalid amount" message"Enter a valid number" preferredStyle:UIAlertControllerStyleAlert];
} else
{ // sets labels
self.interestLabel.text = [NSString stringWithFormat"%i%c",interestRate,percentage];
self.periodLabel.text = [NSString stringWithFormat"%i months",months];
self.totalLabel.text = [NSString stringWithFormat"$%i",(loanAmount + tinterest)];
================================================ ==========================
但是当我运行模拟器时。模拟器上应该有弹出消息。取而代之的是一个错误:
015-10-11 13:56:39.985 iBank[8055:1231178] Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController: 0x7ca82400>)
任何帮助将不胜感激
Best Answer-推荐答案 strong>
试试这个
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");
}];
[ErrorMessage addAction:cancelAction];
[ErrorMessage addActionkAction];
[self presentViewController: ErrorMessage animated:YES completion:nil];
}
else
{
self.interestLabel.text = [NSString stringWithFormat"%i%c",interestRate,percentage];
self.periodLabel.text = [NSString stringWithFormat"%i months",months];
self.totalLabel.text = [NSString stringWithFormat"$%i",(loanAmount + tinterest)];
}
关于ios - UIAlertController 给出错误,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/33064696/
|