0
//tool bar
__strong UIToolbar *tBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,
                                                              self.view.frameHeight-49.0f-44.0f,
                                                              [UIScreen mainScreen].bounds.size.width, 49.0f)];
UITextField* cText = [[UITextField alloc] initWithFrame:CGRectMake(8, 12, 150, 28)];
self.codeText  = cText;
_codeText.backgroundColor = [UIColor whiteColor];
_codeText.placeholder = @"Input code";
[tBar addSubview:_codeText];

UIButton *obtn = [[UIButton alloc] initWithFrame:CGRectMake(180, 12, 60, 28)];
self.okBtn = obtn;
[self.okBtn setTitle:@"OK" forState:UIControlStateNormal];
self.okBtn.titleLabel.textColor = [UIColor whiteColor];
self.okBtn.backgroundColor = [UIColor blueColor];
[self.okBtn addTarget:self action:@selector(confirm) forControlEvents:UIControlEventTouchUpInside];
[tBar addSubview:self.okBtn];

self.cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(250, 12, 60, 28)];
[_cancelBtn setTitle:@"Cancel" forState:UIControlStateNormal];
_cancelBtn.titleLabel.textColor = [UIColor whiteColor];
_cancelBtn.backgroundColor = [UIColor blueColor];
[_cancelBtn addTarget:self action:@selector(cancel) forControlEvents:UIControlEventTouchUpInside];
[tBar addSubview:_cancelBtn];

[self.view addSubview:tBar];

This code is in loadView function in the controller in my project which is enabled ARC;But when I touch any one of the two buttons,it always crash for "EXC_BAD_ACCESS".I had already used zombie to debug,but there is no use for this problem.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
moonToBy
  • 89
  • 1
  • 4
  • is the view loaded inside a tabbarcontroller or navigationcontroller? – Lefteris Apr 19 '12 at 17:19
  • The view is just in a UIViewController; but I use the UIViewController as the paremeter of initWithRootViewController. – moonToBy Apr 19 '12 at 17:24
  • thank you Lefteris! You're my LIFE SAVER! – moonToBy Apr 19 '12 at 17:42
  • You're welcome. Had a similar problem with ARC as well recently :-) – Lefteris Apr 19 '12 at 17:49
  • Hmm, now that I'm looking at the thread I pointed you to, it seems it's pre-ARC code. So the solution would be a bit different for you. It is the same problem, controller get's released by ARC but the solution is this: http://stackoverflow.com/a/9105081/312312 – Lefteris Apr 19 '12 at 17:55

0 Answers0