【发布时间】:2012-03-11 17:58:39
【问题描述】:
我有一个标签栏应用程序。 在其中一个视图(.xib)中,有一个文本字段和一个按钮。该按钮应该保存在 textField 中输入的文本。
但是,无论我输入什么,它总是在调试的 textField.text 中读取 (nil)。
当我右键单击 .xib 中的 textField 时,我无法将 [New Referenceing Outlet] 拖到 [File's Owner]。我只能将 [delegate] 拖到 [File's Owner]。有谁知道为什么我不能这样做?
.h 文件下方:
@interface AddDebtorViewController : UIViewController
{
UITextField *tDebtorName;
}
@property (retain, nonatomic) IBOutlet UITextField *tDebtorName;
-(IBAction)returnButPressed:(id)sender;
-(IBAction)addDebtorButPressed:(id)sender;
@end
下面是.m文件:
#import "AddDebtorViewController.h"
@implementation AddDebtorViewController
@synthesize tDebtorName;
- (IBAction)addDebtorButPressed:(id)sender
{
NSString *debtorName = [[NSString alloc] init];
debtorName = tDebtorName.text;
NSLog(debtorName);
}
...
@end
【问题讨论】:
-
您必须将您的 UITextfield 组件与 tDebtorName Outlet 连接起来。这样您就可以从该文本字段中获取输入
标签: objective-c ios xcode