【问题标题】:Setting UITextField Text设置 UITextField 文本
【发布时间】:2011-03-26 16:15:14
【问题描述】:

我的应用程序中有两个视图由我的RootViewControllerAccountInfoViewController 处理。

我的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 =@"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];

}

【问题讨论】:

    标签: iphone objective-c xcode ios uitextfield


    【解决方案1】:

    我看不到您分配和初始化帐户的位置。您只在显示的代码中声明了它。它是否分配在您的RootViewController 中?是

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

    被叫了?

    【讨论】:

    • 在方法调用中传入。- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { Account *account = [accountTableData objectAtIndex:indexPath.row]; [self editAcctInfo:account]; }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-29
    • 1970-01-01
    相关资源
    最近更新 更多