Я создал перо с TabelViewCell, которое содержит метку и TextField, затем я загружаю эту ячейку в TableView всего двумя строками. Я хочу зафиксировать имя элемента и его цену, поэтому я обновил каждую метку в методе cellForRowAtIndexPath, поскольку у меня есть доступ к значению indexPath.row.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleCellIdentifier = @"AddBudgetItemCell";
SCAddBudgetItemCell *cell = (SCAddBudgetItemCell *)[tableView dequeueReusableCellWithIdentifier:simpleCellIdentifier];
if(cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:simpleCellIdentifier owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.dataTextField.delegate = self;
switch (indexPath.row)
{
case 0:
cell.titleLabel.text = @"Item";
break;
case 1:
cell.titleLabel.text = @"Price ¥";
break;
default:
break;
}
return cell;
}
Однако я не знаю, как я могу получить данные из TextField, поскольку у меня нет доступа ни к созданной мной переменной «ячейка», ни к значению IndexPath.row.