2011-09-22 3 views
0

두 개의 셀을 로그인해야합니다 (사용자 및 비밀번호). 그래서 응용 프로그램을 실행, 다 괜찮아요하지만 UITextField "playerTextField"클릭하면 프로그램이 신호를 받았다 : "EXC_BAD_ACCESS". ? :(코드로 만든 UITextField가 왜 내 tableview Cell 내에서 작동하지 않습니까?

유는 왜 해봤 알고 다른 방법을 많이 읽고 그것을 얻는 방법 I'am 가까이 이것처럼 마십시오

내 코드 :.

사라하려면 버튼/다음 완료를 누르면 경우 키보드. 세포 내부

- (BOOL) textFieldShouldReturn:(UITextField *)textField{ 
    [textField resignFirstResponder]; 
    return YES; 
} 

내 UITextFields.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *kCellIdentifier = @"kCellIdentifier"; 

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
             reuseIdentifier:kCellIdentifier] autorelease]; 
     cell.accessoryType = UITableViewCellAccessoryNone; 



    if ([indexPath section] == 0) { 
      playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)]; 
      playerTextField.adjustsFontSizeToFitWidth = YES; 
      playerTextField.textColor = [UIColor blackColor]; 
      if ([indexPath row] == 0) { 
       playerTextField.placeholder = @"[email protected]"; 
       playerTextField.keyboardType = UIKeyboardTypeEmailAddress; 
       playerTextField.returnKeyType = UIReturnKeyNext; 
       playerTextField.delegate = self; 
      } 
      else { 
       playerTextField.placeholder = @"Requerida"; 
       playerTextField.keyboardType = UIKeyboardTypeDefault; 
       playerTextField.returnKeyType = UIReturnKeyDone; 
       playerTextField.secureTextEntry = YES; 
       playerTextField.delegate = self; 
      }  
      playerTextField.backgroundColor = [UIColor whiteColor]; 
      playerTextField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support 
      playerTextField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support 
      playerTextField.textAlignment = UITextAlignmentLeft; 
      playerTextField.tag = 0; 


      playerTextField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right 
      [playerTextField setEnabled: YES]; 

      //cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20.0]; 
      cell.textLabel.font = [UIFont fontWithName:@"Futura" size:16.0]; 
      cell.textLabel.textColor = [UIColor darkGrayColor]; 
      cell.textLabel.shadowOffset = CGSizeMake(0.5, 0.5); 
      cell.textLabel.shadowColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:10]; 

      [cell.contentView addSubview:playerTextField]; 

      //[playerTextField release]; 
     } 
    } 
    if ([indexPath section] == 0) { // Email & Password Section 
     if ([indexPath row] == 0) { // Email 
      cell.textLabel.text = @"Email"; 
     } 
     else { 
      cell.textLabel.text = @"Contraseña"; 
     } 
    } 
    else { // Login button section 
     cell.textLabel.text = @"Log in"; 
    } 
    return cell;  
} 

답변

0

할당 해제 된 객체에 액세스하려고하면 "EXC_BAD_ACCESS"오류가 발생합니다. 즉, 어딘가에 UITextField에 대한 마지막으로 유지 된 참조가 해제됩니다.

나는 이러한 문제를 일으킬 수있는 코드가 보이지 않습니다.

  • ALLOC - (당신은 아마이 다시 추가해야합니다) 2
  • 릴리스를 유지 - - 1
  • 이 addSubView 유지 도움이 될 것입니다 1

악기를 유지 당신은 어디 파악 문제가 발생합니다. 이 목적을 위해 설계된 '좀비'라는 악기가 있습니다. EXC_BAD_ACCESS에 도달하면 해당 객체가 유지되고 해제 된 코드의 모든 위치가 표시됩니다. 거기에서 당신은 당신이 너무 많이 풀어 놓은 곳을 알아낼 수 있습니다.

+0

답변 해 주셔서 감사합니다. – Panecillo

관련 문제