设置 UITextField 文本
我的应用程序中有两个视图,由 RootViewController
和 AccountInfoViewController
处理。
我的AccountInfoViewController看起来像这样:
#import <UIKit/UIKit.h>
#import "Account.h"
@interface AccountInfoViewController : UIViewController {
IBOutlet UITextField *acctName;
IBOutlet UITextField *acctBalance;
Account *acct;
}
@property (nonatomic, retain) UITextField *acctName;
@property (nonatomic, retain) UITextField *acctBalance;
@property (nonatomic, retain) Account *acct;
-(void) saveAccountInfo;
@end
在我的RootViewController中我正在这样做:
- (void)editAcctInfo:(Account *)acct {
if (self.acctInfoViewController == nil) {
AccountInfoViewController *a = [[AccountInfoViewController alloc]
initWithNibName:@"AccountInfoViewController"
bundle:[NSBundle mainBundle]];
self.acctInfoViewController = a;
[a release];
}
if (acct != nil ) {
self.acctInfoViewController.acct = acct;
}
//Hide Toolbar
[toolbar removeFromSuperview];
[self.navigationController pushViewController:self.acctInfoViewController
animated:YES];
}
这是我的AccountInfoViewController的viewDidLoad方法:
- (void)viewDidLoad
{
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save"
style:UIBarButtonItemStylePlain
target:self
action:@selector(saveAccountInfo:)];
acctBalance.text = acct.balance.accessibilityValue;
acctName.text = acct.name.accessibilityValue;
//acctName.text = @"Test Text";
self.title =@"Edit Account";
self.navigationItem.rightBarButtonItem = saveButton;
[super viewDidLoad];
}
当我运行此命令时,我的视图的 UITextFields 中什么也没有得到。如果我用“测试文本”取消注释该行,在我看来这看起来很好,所以我知道我有一部分是正确的。 调试时可以看到acct下的值。当我实际上将鼠标悬停在代码中的单词 acct 上时,我得到所有值的“无效摘要”。
知道我做错了什么或者是否有更好的方法来实现这一点?我知道这一定是我在 AccountInfoViewController
中设置“acct”属性的问题。
这就是我调用上面 editAcctInfo
方法的方式:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Account *account = [accountTableData objectAtIndex:indexPath.row];
[self editAcctInfo:account];
}
I have two views in my application handled by my RootViewController
and AccountInfoViewController
.
My AccountInfoViewController
looks like this:
#import <UIKit/UIKit.h>
#import "Account.h"
@interface AccountInfoViewController : UIViewController {
IBOutlet UITextField *acctName;
IBOutlet UITextField *acctBalance;
Account *acct;
}
@property (nonatomic, retain) UITextField *acctName;
@property (nonatomic, retain) UITextField *acctBalance;
@property (nonatomic, retain) Account *acct;
-(void) saveAccountInfo;
@end
In my RootViewController
I am doing this:
- (void)editAcctInfo:(Account *)acct {
if (self.acctInfoViewController == nil) {
AccountInfoViewController *a = [[AccountInfoViewController alloc]
initWithNibName:@"AccountInfoViewController"
bundle:[NSBundle mainBundle]];
self.acctInfoViewController = a;
[a release];
}
if (acct != nil ) {
self.acctInfoViewController.acct = acct;
}
//Hide Toolbar
[toolbar removeFromSuperview];
[self.navigationController pushViewController:self.acctInfoViewController
animated:YES];
}
Here is my viewDidLoad
method of my AccountInfoViewController
:
- (void)viewDidLoad
{
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save"
style:UIBarButtonItemStylePlain
target:self
action:@selector(saveAccountInfo:)];
acctBalance.text = acct.balance.accessibilityValue;
acctName.text = acct.name.accessibilityValue;
//acctName.text = @"Test Text";
self.title =@"Edit Account";
self.navigationItem.rightBarButtonItem = saveButton;
[super viewDidLoad];
}
When I run this, I get nothing in my UITextFields
of my view. If I uncomment the line with the "Test Text", that appears fine in my view so I know I have part of it right.
When debugging, I can see the values under acct. When I actually hover over the word acct in the code, I get "Invalid Summary" for all the values.
Any idea what I'm doing wrong or if there is a better way to accomplish this? I know it must be a problem with how I am setting the "acct" property in my AccountInfoViewController
.
This is how I call the above editAcctInfo
method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Account *account = [accountTableData objectAtIndex:indexPath.row];
[self editAcctInfo:account];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我看不到你在哪里分配和初始化你的帐户。您仅在所显示的代码中声明了它。它是否在您的
RootViewController
中分配?正在接到电话吗?
I can't see where you alloc and init your account. You have only declared it in the code you're showing. Is it allocated in your
RootViewController
? isgetting called?