gpt4 book ai didi

iphone - UITextField 在 UITableView 中滚动时清除 - 自定义单元格

转载 作者:行者123 更新时间:2023-12-01 16:54:43 25 4
gpt4 key购买 nike

我试图从 UITextField 中保存某些值,但是我无法做到这一点,因为每当我滚动时,UITextField 中什么都没有。我正在使用自定义单元格。我知道自定义单元格必须加载到特定 View 中,因此我使用 textFieldDidEndEditing 将值存储在数组中。但是,我收到以下错误消息:
* 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“* -[__NSArrayM insertObject:atIndex:]: 对象不能为 nil'

非常感谢您的帮助!我的代码在下面,我在 IOS 开发中很新。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

if (indexPath.section == 0) {
if (indexPath.row == 7) {
static NSString *CellIdentifier = @"RevButtonCell";

RevButtonCell *cell = (RevButtonCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"RevButtonCell" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
[cell.revsaveB addTarget:self action:@selector(revaddparse:) forControlEvents:UIControlEventTouchUpInside];

cell.reveditdeleteB.hidden = YES;
cell.reveditsaveB.hidden = YES;
cell.revsaveB.hidden = NO;
cell.revdeleteB.hidden = NO;

}
return cell;
} else {

static NSString *CellIdentifier = @"TextCell";

TextCell *cell = (TextCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"TextCell" owner:self options:nil];
cell = [topLevelObjects objectAtIndex:0];
}

cell.detaillabel.text = [revdetailsA objectAtIndex:indexPath.row];

cell.detailtext.placeholder = @"Enter Text";
cell.detailtext.tag = indexPath.row;
cell.detailtext.delegate = self;

if (indexPath.row == 0) {
cell.detailtext.text = dateS;
}
if (indexPath.row == 1) {
cell.detailtext.text = clientS;
}
if (indexPath.row == 2) {
cell.detailtext.text = productS;
}
if (indexPath.row == 3) {
cell.detailtext.text = amountS;
}
if (indexPath.row == 4) {
cell.detailtext.text = qtyS;
}
if (indexPath.row == 5) {
cell.detailtext.text = taxS;
}
if (indexPath.row == 6) {
cell.detailtext.text = totalS;
}

cell.selectionStyle = UITableViewCellSelectionStyleNone;

return cell;
}
}
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
[client insertObject:clientS atIndex:0];
[product insertObject:productS atIndex:0];
[date insertObject:dateS atIndex:0];
[amount insertObject:amountS atIndex:0];
[qty insertObject:qtyS atIndex:0];
[tax insertObject:taxS atIndex:0];
[total insertObject:totalS atIndex:0];
}

最佳答案

将 vales 初始化为空字符串

clientS = @"";
productS = @"";
dateS = @"";
amountS = @"";
qtyS = @"";
taxS = @"";
totalS = @"";

关于iphone - UITextField 在 UITableView 中滚动时清除 - 自定义单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12684316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com