gpt4 book ai didi

iphone - 如何比较自定义 UITableViewCel 中的标签是否为空?

转载 作者:行者123 更新时间:2023-11-29 04:40:47 26 4
gpt4 key购买 nike

我有一个带有 2 个日期标签的自定义 TableViewCell,当 coreData 未保存任何内容时,我的日期标签应该选择一个示例日期。但是当设置日期时,我想在我的标签中显示它。我用下面的代码尝试过,但无法正常工作。

你能帮我吗?

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"produktCell";


ProduktTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[ProduktTableViewCell alloc] initWithFrame:CGRectZero];
}
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];


cell.produktnameLabel.text = [managedObject valueForKey:@"produktname"];
NSLog(@"%@",cell.vonDatumLabel.text);

if ([cell.vonDatumLabel.text length] > 1){
cell.vonDatumLabel.text = [managedObject valueForKey:@"vondatum"];
cell.bisDatumLabel.text = [managedObject valueForKey:@"bisdatum"];

}else {
cell.vonDatumLabel.text = dateString;
cell.bisDatumLabel.text = dateString1;
}



cell.datumButton.tag = indexPath.row;
cell.warenkorbButton.tag = indexPath.row;
cell.menge.tag = indexPath.row + 437812;
cell.mengeLabel.text = [managedObject valueForKey:@"mengelabel"];




NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSLocale *german = [[NSLocale alloc] initWithLocaleIdentifier:@"de_DE"];
[formatter setLocale:german];
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[formatter setMinimumFractionDigits:2];
[formatter setMaximumFractionDigits:2];


NSNumber *firstNumber = [managedObject valueForKey:@"preis"];

cell.preisLabel.text = [formatter stringFromNumber:firstNumber];



return cell;
}

最佳答案

Make if condition like this 

if ([[managedObject valueForKey:@"produktname"] length] > 1){
cell.vonDatumLabel.text = [managedObject valueForKey:@"vondatum"];
cell.bisDatumLabel.text = [managedObject valueForKey:@"bisdatum"];

}else {
cell.vonDatumLabel.text = dateString;
cell.bisDatumLabel.text = dateString1;
}

Surely this will help ful

关于iphone - 如何比较自定义 UITableViewCel 中的标签是否为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10426811/

26 4 0