0
我在我的应用程序中有两个视图,分别由我的RootViewController
和AccountInfoViewController
处理。设置UITextField文本
我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 [email protected]"Edit Account";
self.navigationItem.rightBarButtonItem = saveButton;
[super viewDidLoad];
}
当我运行这个,我在我的里什么都没有我的看法。如果我用“测试文本”取消注释,在我看来这看起来很好,所以我知道我有一部分是正确的。 调试时,我可以看到acct下的值。当我真的将鼠标悬停在代码中的单词acct上时,我得到了所有值的“无效摘要”。
任何想法我做错了什么,或者如果有更好的方法来实现这一点?我知道在我的AccountInfoViewController
中设置“acct”属性时,这肯定是个问题。
这是我如何调用上面editAcctInfo
方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
Account *account = [accountTableData objectAtIndex:indexPath.row];
[self editAcctInfo:account];
}
它是在该方法call.-(无效)传递的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath { 帐户*帐户= [accountTableData objectAtIndex:indexPath.row]; [self editAcctInfo:account]; } – 2011-03-26 17:35:05