0
創建我試圖改變的UITextField一個TableView中代表
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
// Configure cell here
if (indexPath.section == [self nameSectionNumber]) {
if (indexPath.row == [self firstNameRowNumber]){
UITextField *textFieldFromCell = [self retrieveUITextFieldFromCell:cell];
textFieldFromCell.text = [self.person firstName];
} else if (indexPath.row == [self lastNameRowNumber]) {
cell.textLabel.text = [self.person lastName];
}
} else if (indexPath.section == [self emailSectionNumber]) {
if (indexPath.row == [self emailSectionHomeRowNumber]) {
cell.textLabel.text = [self.person homeEmail];
} else if (indexPath.row == [self emailSectionWorkRowNumber]) {
cell.textLabel.text = [self.person workEmail];
}
}
return cell;
}
- (UITextField *)retrieveUITextFieldFromCell:(UITableViewCell *)cell
{
// Need to grab UITextField from cell
for (UIView *view in cell.contentView.subviews){
if ([view isKindOfClass:[UITextField class]]){
UITextField* txtField = (UITextField *)view;
return txtField;
}
}
return nil;
}
如果我不嘗試修改單元格,只是做
// Configure cell here
if (indexPath.section == [self nameSectionNumber]) {
if (indexPath.row == [self firstNameRowNumber]){
cell.textLabel.text = [self.person firstName];
} else if (indexPath.row == [self lastNameRowNumber]) {
cell.textLabel.text = [self.person lastName];
}
}
中的UILabel(「名」)消失,且的UITextField消失了,這是我所期望的,因爲我認爲它因爲這個代碼
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
注:忽略過去的姓名和電子郵件領域。目前我只專注於名字,以使其看起來很正確。
'cell.textLabel.text.text'? – nhgrif
你想要做什麼,或者你的問題是什麼都不清楚。 – rdelmar
@nhgrif修正:) – envinyater