【发布时间】:2011-08-10 15:40:16
【问题描述】:
我有一个使用以下代码触发的 PromoCodeViewController:
@implementation Demo_WebServiceCallingUsingiOSAppDelegate
@synthesize window = _window,promoCodeController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.promoCodeController = [[PromoCodeViewController alloc] init];
[self.window addSubview:self.promoCodeController.view];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
PromoCodeViewController 包含 UITextField,我为 PromoCodeViewController 实现 UITextFieldDelegate,如下所示:
@interface PromoCodeViewController : UIViewController<UITextFieldDelegate>
{
IBOutlet UITextField *promoCodeTextField;
}
@property (nonatomic,retain) IBOutlet UITextField *promoCodeTextField;
@end
我实现了textFieldShouldReturn方法如图:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
return TRUE;
}
我什至将 PromoCodeViewController 设置为 UITextField 事件的委托。当我开始在文本框中输入时,它会抛出“程序接收到的信号。EXC_BAD_ACCESS”。当我在 UITextField 中键入第二个字符时会发生这种情况。我做错了什么?
更新1:
错误出现在以下部分:
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([Demo_WebServiceCallingUsingiOSAppDelegate class]));
}
}
【问题讨论】:
-
我认为您不应该在第一个代码块中将窗口设置为 promoCodeViewController ... 虽然我认为这不是导致您的错误的原因。
-
崩溃时的堆栈跟踪是什么?
-
@sergio 堆栈跟踪中没有任何内容!
-
见我的answer here。我曾经遇到过同样的问题,它似乎与模拟器 SDK 中的错误有关。
-
据我所知,EXC_BAD_ACCESS 错误是由于尝试访问不再存在的内容、IE 保留不足或提前发布造成的。看起来您发布的代码没有类似的错误,所以它必须在其他地方。您是否检测到在代码中的任何位置输入的文本?尝试为自己放置一些断点或 NSLog 消息,然后发布结果。
标签: objective-c ios4