objective-c - 尝试将文本字段文本设置为字符串时出错

标签 objective-c error-handling nsstring uitextfield

我正在尝试将我的文本字段的文本设置为等于已保存的字符串。我将其全局设置,因为我需要在另一点访问它。我收到此错误: Undefined symbols for architecture arm64: "_tailNum", referenced from: -[rvc newPlaneClicked:] in rvc.o "_MM", referenced from: -[rvc newPlaneClicked:] in rvc.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
是什么导致此问题/如何解决?

extern NSString *tailNum;
extern NSString *MM;

- (void)newPlaneClicked:(id)sender {

    UIAlertView *newPlaneAlert = [[UIAlertView alloc]initWithTitle:@"FlightLog Pro" message:@"Enter tail number and make/model:"delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Save", nil];

    newPlaneAlert.delegate = self;
    [newPlaneAlert setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];

    UITextField *enterNewPlaneTail = [newPlaneAlert textFieldAtIndex:0];
    UITextField *enterNewPlaneMM = [newPlaneAlert textFieldAtIndex:1];

    [enterNewPlaneTail setPlaceholder:@"Click to enter a make/model."];
    [enterNewPlaneMM setPlaceholder:@"Click to enter a plane tail number."];

    [newPlaneAlert textFieldAtIndex:0].autocapitalizationType = UITextAutocapitalizationTypeSentences;
    [newPlaneAlert textFieldAtIndex:0].autocorrectionType = YES;

    [newPlaneAlert textFieldAtIndex:1].autocapitalizationType = UITextAutocapitalizationTypeSentences;
    [newPlaneAlert textFieldAtIndex:1].autocorrectionType = YES;
    [newPlaneAlert textFieldAtIndex:1].secureTextEntry = NO;

    [newPlaneAlert show];

    enterNewPlaneTail.text = tailNum;
    enterNewPlaneMM.text = MM;
}

最佳答案

放这些声明

extern NSString *tailNum;
extern NSString *MM;

放入.h文件中,并在.m文件的全局范围内为其分配一些值:
NSString *tailNum = @"tailNum";
NSString *MM      = @"MM";

另请参阅有关外部变量的更多信息。您可以从Wikipedia开始。 Here是另一种解释

关于objective-c - 尝试将文本字段文本设置为字符串时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24579899/

相关文章:

iphone - 从响应 NSString 中获取子字符串

ios - 后台 UIDevice CFDictionaryGetValue 错误

ios - 以编程方式自动将整数添加到 UILabel 中?可能的?

objective-c - 在 OSX 10.8 SDK/objective-c 中拖动一个按钮

ios - iOS 中的调整大小问题

iphone - 仅替换 NSString 中子字符串的第一个实例

vb.net - 单独使用的 “Throw”关键字实际上有什么作用

使用自定义错误处理程序捕获 Javascript 错误后,Angular/Angular2 数据绑定(bind)不起作用

error-handling - 如何返回带有一般错误的结果

debugging - NSDictionary 和 NSURL 的 Objective-C 问题