ฉันสร้างปลายปากกาด้วย 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