gpt4 book ai didi

objective-c - 从 'NSString *'(又名 'NSInteger')分配给 'int' 的指针转换不兼容的整数;

转载 作者:行者123 更新时间:2023-12-02 22:40:26 25 4
gpt4 key购买 nike

在表格单元格 View 中显示 xml 解析数据时遇到此语义问题。应用程序成功运行,但是当我选择任何行时,应用程序进入详细 View ,此时应用程序崩溃。请帮忙!!!

这行第三种情况出现语义问题

cell.textLabel.text = aBook.bookID;

应用代码:

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

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}

switch (indexPath.section) {
case 0:
cell.textLabel.text = aBook.name;
break;
case 1:
cell.textLabel.text = aBook.author;
break;
case 2:
cell.textLabel.text = aBook.price;
break;
case 3:
cell.textLabel.text = aBook.bookID;
break;
}

return cell;
}

最佳答案

可能你的 aBook.bookID 变量是一个 NSInteger,要将它转换成 NSString 使用这个:

case 3:            
cell.textLabel.text = [NSString stringWithFormat:@"%i", aBook.bookID];
break;

关于objective-c - 从 'NSString *'(又名 'NSInteger')分配给 'int' 的指针转换不兼容的整数;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10848257/

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