2011-03-26 80 views
0

我在我的应用程序中有两个视图,分别由我的RootViewControllerAccountInfoViewController处理。设置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]; 
} 

这里是我的我的AccountInfoViewControllerviewDidLoad方法:

- (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]; 

} 

回答

0

我不能看到你的alloc和init您的帐户。您只在您展示的代码中声明了它。它是否分配在您的RootViewController?是

if (acct != nil) { 
    self.acctInfoViewController.acct = acct; 
} 

被调用?

+0

它是在该方法call.-(无效)传递的tableView:(UITableView的*)的tableView didSelectRowAtIndexPath方法:(NSIndexPath *)indexPath { 帐户*帐户= [accountTableData objectAtIndex:indexPath.row]; [self editAcctInfo:account]; } – 2011-03-26 17:35:05