Mam pięć pól konfiguracji na kontrolerze rejestracji. Nazwa użytkownika, nazwa wyświetlana, hasło, potwierdź hasło i adres e-mail.Uzyskiwanie dostępu do atrybutów komórki poza komórkąForRowAtIndexPath
Są setup z następujących czynności:
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.textColor = [UIColor colorWithRed:14.0f/255.0f green:62.0f/255.0f blue:178.0f/255.0f alpha:0.8f];
cell.textLabel.font = [UIFont boldSystemFontOfSize:13.0f];
switch (indexPath.row) {
case 0: {
cell.textLabel.text = NSLocalizedString(@"UsernameFieldLabel", @"Username field label");
[cell addSubview:self.usernameField];
break ;
}
case 1: {
cell.textLabel.text = NSLocalizedString(@"DisplayNameFieldLabel", @"Displayname field lael");
[cell addSubview:self.displayNameField];
break ;
}
case 2: {
cell.textLabel.text = NSLocalizedString(@"PasswordFieldLabel", @"Password field lael");
[cell addSubview:self.passwordField];
break ;
}
case 3: {
cell.textLabel.text = NSLocalizedString(@"ConfirmPasswordFieldLabel", @"Confirm Password field lael");
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 2;
[cell addSubview:self.confirmPasswordField];
break ;
}
case 4: {
cell.textLabel.text = NSLocalizedString(@"EmailFieldLabel", @"Email field lael");
[cell addSubview:self.emailField];
break ;
}
}
return cell;
Komórki sami działać prawidłowo. Następnie mam kilka sprawdzania poprawności na przycisku, który sprawdza poprawny adres e-mail itp., To również działa dobrze.
Co chciałbym móc zrobić, to zaktualizować atrybut cell.textLabel.textColor w kodzie sprawdzania poprawności. Na przykład, jeśli adres e-mail nie jest prawidłowy, chcę zaktualizować kolor tekstu etykiety na czerwony, tak aby się wyróżniał (sortuję też odpowiedź itp.).
Jak uzyskać odniesienie do tej konkretnej komórki poza konfiguracją komórek?
EDYCJA Jest to zmiana wynikająca z odpowiedzi. Muszę uzyskać dostęp do 5th CLL (ścieżka indeks 4) w pkt 1 (tylko jednej sekcji w widoku tabeli):
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:4 inSection:1];
UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.textLabel.textColor = [UIColor redColor];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
Zmień NSIndexPath * indexPath = [NSIndexPath indexPathForRow: 4 inSection: 1]; jako NSIndexPath * indexPath = [NSIndexPath indexPathForRow: 4 inSection: 0]; –