Почему мой UITextField, созданный кодом, не работает внутри моей ячейки табличного представления? - PullRequest
0 голосов
/ 22 сентября 2011

Я хочу две ячейки для входа в систему (пользователь и пароль). Итак, я запускаю приложение, все в порядке, но когда я нажимаю в UITextField «playerTextField», программа получает этот сигнал: «EXC_BAD_ACCESS». (

Ты знаешь почему? Я пробовал и читал много разных способов, и именно так я ближе к нему.

Мой код:

Чтобы пропустить клавиатуру, если нажата кнопка Далее / Готово.

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

Мои поля UITextField внутри ячеек.

- (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 = @"ejemplo@gmail.com";
                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;    
}

1 Ответ

0 голосов
/ 22 сентября 2011

Ошибки «EXC_BAD_ACCESS» возникают при попытке доступа к объекту, который был освобожден.Это означает, что где-то освобождается последняя сохраненная ссылка на ваш UITextField.

В видимом коде я не вижу ничего, что могло бы вызвать такую ​​проблему.

  • alloc - сохранение 1
  • addSubView - сохранение выпуска 2
  • (возможно, вам следует добавить это обратно) - сохранение 1

Инструменты должны помочь вам выяснить, где возникает проблема.Существует инструмент под названием «Зомби», который предназначен именно для этой цели.Когда вы достигнете EXC_BAD_ACCESS, он покажет вам все места в вашем коде, где этот объект был сохранен и освобожден.Оттуда вы можете выяснить, где вы выпустили слишком много раз (или, возможно, забыли сохранить его).

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...