[英]Incompatible Integer to pointer conversion sending 'NSInteger' (aka 'int') to parameter of type 'NSInteger *' (aka 'int *')
[英]Incompatible integer to pointer conversion assigning to 'NSString *' from 'NSInteger' (aka 'int');
在表格單元格視圖中顯示xml解析數據時出現了語義問題。 應用程序成功運行,但是當我選擇任何行時,應用程序都會進入詳細視圖,此時應用程序將崩潰。 請幫助!!!
語義問題在該行的第三種情況下發生
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;
您的情況3取決於您的bookID
對於int
cell.textLabel.text = [NSString stringWithFormat:@"%d",aBook.bookID];
對於NSInteger
cell.textLabel.text = [NSString stringWithFormat:@"%i",aBook.bookID];
因為您正在為字符串提供int值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.