【发布时间】:2015-06-13 19:31:25
【问题描述】:
我正在创建一个这样的视图实例...
- (IBAction)findPatientTapped:(id)sender {
RequestDialogViewController *findPatientViewController = [[RequestDialogViewController alloc] initWithNibName:@"RequestDialogViewController" bundle:nil];
findPatientViewController.delegate = self;
findPatientViewController.autoCorrectOff = YES;
findPatientViewController.defaultResponse = @"";
findPatientViewController.keyboardType = @"ASCII";
findPatientViewController.returnKeyType = @"Go";
findPatientViewController.tag = findRequestTag;
findPatientViewController.editSet = YES;
findPatientViewController.titleText = @"Find Patient";
findPatientViewController.messageText =@"Enter all or a portion of the patient's name...";
findPatientViewController.messageText2 = @"Last Name...";
findPatientViewController.messageText3 = @"First Name...";
findPatientViewController.showResponse2 = YES;
findPatientViewController.showNavBarSaveButton = NO;
findPatientViewController.infoTextFile = @"";
findPatientViewController.view.frame = CGRectMake(280, 230, 480, 300);
[self.view addSubview:findPatientViewController.view];
}
视图包含 2 个 UITextField 字段供用户输入。在运行转换为 ARC 工具之前,这一切都很好。转换后,视图在尝试在两个字段中的任何一个中输入值时崩溃...
-[RequestDialogViewController respondsToSelector:]:消息发送到释放的实例
这是运行转ARC工具后UIViewController的.h文件...
#import <UIKit/UIKit.h>
@protocol RequestDialogViewControllerDelegate;
@interface RequestDialogViewController : UIViewController <UITextFieldDelegate>{
id<RequestDialogViewControllerDelegate> __weak delegate;
IBOutlet UINavigationBar *navBar;
IBOutlet UITextField *response;
IBOutlet UITextField *response2;
IBOutlet UILabel *message;
IBOutlet UILabel *message2;
IBOutlet UILabel *message3;
IBOutlet UIButton *saveButton;
NSTimer *selectAllTimer;
NSString *defaultResponse;
NSString *titleText, *infoTextFile;
NSString *messageText, *messageText2, *messageText3;
NSString *placeHolderText;
NSString *keyboardType, *returnKeyType;
BOOL editSet, showSaveButton,showNavBarSaveButton, showResponse2, autoCorrectOff;
int tag;
}
@property (weak) id<RequestDialogViewControllerDelegate> delegate;
@property (nonatomic, strong)IBOutlet UITextField *response;
@property (nonatomic, strong) IBOutlet UITextField *response2;
@property (nonatomic, strong)IBOutlet UILabel *message;
@property (nonatomic, strong)IBOutlet UILabel *message2;
@property (nonatomic, strong) IBOutlet UILabel *message3;
@property (nonatomic, strong)IBOutlet UIButton *saveButton;
@property (nonatomic, strong)NSString *defaultResponse;
@property (nonatomic, strong)NSString *titleText, *infoTextFile;
@property (nonatomic, strong)NSString *messageText, *messageText2, *messageText3;
@property (nonatomic, strong)NSString *placeHolderText;
@property (nonatomic, strong)NSString *keyboardType, *returnKeyType;
@property (nonatomic, strong)IBOutlet UINavigationBar *navBar;
@property (readwrite)BOOL editSet, showSaveButton, showNavBarSaveButton, showResponse2, autoCorrectOff;
@property (readwrite)int tag;
@property (nonatomic, strong) NSTimer *selectAllTimer;
- (IBAction)saveButtonPressed:(id)sender;
- (void)selectAll;
- (IBAction)editingDidEnd:(id)sender;
@end
@protocol RequestDialogViewControllerDelegate <NSObject>
@optional
- (void)requestDialogViewDidDismiss:(RequestDialogViewController *)controller withResponse:(NSString*)reqResponse response2:(NSString*)reqResponse2;
@end
这是创建 RequestDialog 视图实例的类的 .h 文件中的相关引用...
#import "RequestDialogViewController.h"
@interface OrthoViewController : UIViewController <RequestDialogViewControllerDelegate>{
}
- (void)requestDialogViewDidDismiss:(RequestDialogViewController *)controller withResponse:(NSString*)reqResponse response2:(NSString*)reqResponse2;
@end
我需要做什么才能在 ARC 下进行这项工作?我认为这可能与协议的形成方式有关。
谢谢,
约翰
**** 感谢 Dan,我通过使 findPatientViewController 成为调用类的属性来解决了这个问题...
RequestDialogViewController *findPatientViewController;
@implementation OrthoViewController
- (IBAction)findPatientTapped:(id)sender {
findPatientViewController = [[RequestDialogViewController alloc] initWithNibName:@"RequestDialogViewController" bundle:nil];
//set all the properties and add the subview
}
@end
【问题讨论】:
标签: ios objective-c xcode6 automatic-ref-counting