在IBAction中设置UITextField的值

时间:2011-04-24 21:10:35

标签: iphone cocoa-touch interface-builder xcode4

我正在尝试使用UITextField作为简单加密的输出。该字段以nil字符串(默认行为)开头,我尝试在encryptButtonPressed:操作中更新它。我知道我正在将一个好的NSString转换成密文,并且我没有收到错误或警告或该方法不存在的任何内容,但该字段仍为空白。有什么想法吗?

这是标题:

@interface FirstViewController : UIViewController <UITextFieldDelegate> {


    IBOutlet UITextField *affineKeyField;
    IBOutlet UITextField *shiftKeyField;

    IBOutlet UITextField *messageField;
    IBOutlet UITextField *ciphertextField;

    MAAffineMachine* machine;
}

@property (nonatomic, retain) UITextField *affineKeyField;
@property (nonatomic, retain) UITextField *shiftKeyField;

@property (nonatomic, retain) UITextField *messageField;
@property (nonatomic, retain) UITextField *ciphertextField;


@property (nonatomic, retain) UIButton *encryptButton;
@property (nonatomic, retain) UIButton *clipboardButton;

- (IBAction)encryptButtonPressed:(id)sender;
- (IBAction)clipboardButtonPressed:(id)sender;

@end

动作,在控制器的实现中定义:

- (IBAction)encryptButtonPressed:(id)sender {
    NSLog(@"Encrypt Button pushed.\n");
    int affine = [[affineKeyField text] intValue];
    int shift = [[shiftKeyField text] intValue];
    NSString* message = [messageField text];
    NSLog(@"%d, %d, %@", affine, shift, message);
    NSString* ciphertext = [machine encryptedStringFromString:message
                                                    ForAffine:affine
                                                        Shift:shift];
    NSLog(@"%@\n", ciphertext);
    [[self ciphertextField] setText: ciphertext];
}

2 个答案:

答案 0 :(得分:0)

尝试[[self ciphertextField] setText:ciphertext] - &gt; [ciphertextField setText:ciphertext]或cipherTextField.text = ciphertext;

答案 1 :(得分:0)

如果ciphertext具有正确的值,则应检查接口构建器中是否正确链接了ciphertextField