YES 和 NO 按钮功能按预期工作,唯一的问题是问题 No GPS hardware use Triangulation?
没有出现以告知用户警报的内容。该应用程序是选项卡式的。
项目的全部代码包括 xcode 项目文件和 Info.plist 文件可以是 发现于 GitHub ,以防您想要构建或调试它。
以下 UIAlertController 的 UIAlertController 的标题和消息不会出现:
- (UIAlertController*) alertUserNoGPSHardware {
UIAlertController *alertToPresent = nil;
NSString* alertTitleString = @"GPS Alert";
NSString* alertMessage = @"No GPS hardware use Triangulation?";
if (!hardwareExistsOnDevice && mustUseGPSHardware) {
alertToPresent = [UIAlertController alertControllerWithTitle: alertTitleString message:alertMessage
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* yesButton = [UIAlertAction actionWithTitle:@"YES" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {mustUseGPSHardware = NO;}];
[alertToPresent addAction:yesButton];
UIAlertAction* noButton = [UIAlertAction actionWithTitle:@"NO" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {mustUseGPSHardware = YES;}];
[alertToPresent addAction:noButton];
}
return alertToPresent;
}
我还尝试将上述代码嵌入到调用此库例程的函数中。出现同样的问题。
- (void) setLabelWithGPSLatitudeAndLongitudeWithTimeStampData {
NSString *actionString = nil;
if (displayDataModel) {
if (isFirstGpsClick) {
// Call to the DataModel library that receives a pointer UIAlertView object from the GPS library implementation
// If the UIAlertView pointer is nil proceed with the displaying the latitude, longitude and timestamp.
// If the UIAlertView has a value show the alert, the alert should contain a function to update data in the GPS model.
// This will enable the user to approve of using WiFi or Radio triangulation when the GPS is not available.
/*
* BUG - title and message are not appearing in the alert, the buttons in the alert work as expected
* clicking the YES button removes the warning message that there is no GPS hardware and just
* returns the data. Clicking the no message displays displays the warning message every time.
*/
isFirstGpsClick = NO;
UIAlertController* gpsAlert = [displayDataModel provideGPSAlerters];
if (gpsAlert) {
[self presentViewController:gpsAlert animated:NO completion:nil];
return;
}
}
actionString = [displayDataModel provideGPSLocationData];
}
else {
actionString = @"GPS Button Action Failure: Data Model not created";
}
[displayButtonAction setText:actionString];
}
我还尝试将嵌入式代码移动到以下 2 个函数中
- (void)viewWillLayoutSubviews {
/*
* Get the tab bar height from the Application Delegate so that the total vertical space
* can be calculated.
*/
AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
if (appDelegate) {
UITabBarController *TempTabBar = appDelegate.tabBarController;
if (TempTabBar) {
// Tab Bar Height is larger than myDelegate.tabBarController.tabBar.frame.size.height indicates
tabBarHeight = TempTabBar.tabBar.frame.size.height * 2.5;
}
}
[self setSubViewSizeVariablesBasedOnViewBounds];
[self addButtonAndLabels];
self.view.backgroundColor = [UIColor whiteColor];
}
- (void)viewDidLoad {
[super viewDidLoad];
if (self.displayModelLibraryInitialization) {
NSLog(@"In Objective-C Implementation viewDidLoad - unable to initialize displayModelLibrary");
}
}
当我将 UIAlertController 移动到 viewWillLayoutSubviews() 或 viewDidLoad() 时,我得到黑屏,而不是 警报,而不是应该在那里的按钮和标签。
This question不适用,因为当前问题出在 Objective-c 而不是 Swift。
This question不适用,因为没有文本字段正在更新。
该代码不使用警报生成器,所以 this question不适用。
背景
我是 Xcode、iOS、Objective-c 和 Swift 编程的新手。这是我的第一个 iOS 项目。它是 面试编码挑战。
OSX - 埃尔卡皮坦 Xcode - 版本 8.2 (8C38) 在模拟器中运行。
最佳答案
我只是回答这个问题,这样它就不会添加到 StackOverflow 未回答的问题中(在 CodeReview 上,我们将未回答的问题称为僵尸)。
@DavidH 帮助提供了答案。
Xcode 8.2 中的 iPhone 7 plus 模拟器似乎有一些小问题。 DavidH 能够在 Xcode 8.3 中的 iPhone 7 模拟器
的警报中看到消息。我从 iPhone 7 plus 模拟器切换到 iPhone 7 模拟器,并在警报中看到了消息。
这表明代码中可能没有问题,Xcode 8.2 中的 iPhone 7 plus 模拟器
可能 存在错误。
关于ios - UIAlertController 标题和消息不会出现在 Xcode 8.2 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43724711/