- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"inventoryItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.font = [UIFont systemFontOfSize:15];
}
UILabel *name = (UILabel *)[cell viewWithTag:1];
NSLog(@"%@", name.text);
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return inventoryItems.count;
}
我意识到这与dequeueReuasableCellWithIdentifier有关,但我不确定如何解决这个问题。我在故事板上有文本字段然后我有一个动作将所有这些文本字段相对于它们的单元格发送到数据库。文本字段的代码在IBAction中发送数据并存储。我将添加IBAction代码:
- (IBAction)submitCountTapped:(id)sender {
NSMutableDictionary *dic;
if(inventoryItems.count>0){
NSMutableArray *prods = [[NSMutableArray alloc] init];
for (int a=0; a<inventoryItems.count; a++) {
if([inventoryItems[a] objectForKey:@"InventoryID"]!=nil){
UITableViewCell *cell = [_tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:a inSection:0]];
UITextField *countTextfield = (UITextField *)[cell viewWithTag:4];
double countValue = [countTextfield.text doubleValue];
NSNumber *count = [NSNumber numberWithDouble:countValue];
dic = [NSMutableDictionary dictionaryWithObjectsAndKeys: [self fetchDict:@"CustomerData"][@"User_ID"], @"User_ID", count, @"manual_quantity", inventoryItems[a][@"InventoryID"], @"InventoryID", nil];
[prods addObject:dic];
}
}
NSDictionary *outerDic = @{@"Data":prods};
if([self isInternet]){
[self fetchPostAddress:[NSString stringWithFormat:@"http://localhost/Backend/webservice/set-inventory-manually.php"] andParameter:[self jsonconvert:outerDic]andIdentifier:@"manualInventory"];
}
}
}
答案 0 :(得分:0)
从自定义单元格创建自定义UITableViewCell
类。
在tableView: cellForRowAtIndexPath:
ConditionTableViewCell *objCell = (ConditionTableViewCell *) [tableView dequeueReusableCellWithIdentifier:@"conditionCell"];
objCell.countTextfield.text = @"Your text";
return objCell;