【问题标题】:Exception when load table containing data from sqlite3加载包含来自 sqlite3 的数据的表时出现异常
【发布时间】:2012-04-17 13:07:09
【问题描述】:

我正在开发 iPhone 应用程序,我创建了一个视图控制器,其中包含一个按钮和 tableViewController 必须显示数据形式 sqlite3 ,我使用的是 xcode 3.4 我想要 viewController 中的按钮打开 TableViewController ,当我尝试在没有按钮的情况下打开该表本身时,我转到情节提要并将原始数据放在 TableViewController 上,它会正常加载 sqlite 的数据 但是当我将 raw 放在 viewController 上并将按钮连接到 TableViewController 并使连接模式然后运行时..当我按下按钮时,它给了我以下异常: NSInvalidArgumentException', reason: '-[NSIndexPath isEqualToString:]: unrecognized selector sent to instance ...

异常是指 (cellForRowAtIndexPath) 中的一行

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

Books *temp= (Books *)[self.books objectAtIndex:indexPath.row];


// [cell setText:temp.bo_name];
[cell setText:[NSString stringWithFormat:@"%d - %@ - %d - %d - %d - %d - %@ - %f - %f - %@ - %f - %d - %@ - %d",temp.bo_id, temp.bo_name, temp.bo_au_id, temp.bo_pub_id, temp.bo_num_pages, temp.bo_publish_year, temp.bo_about, temp.bo_price, temp.bo_currency, temp.bo_cover_img, temp.bo_recomended, temp.bo_sec_id, temp.bo_path, temp.bo_sort]];

return cell;

}

编辑以添加在我的答案 - JeremyP 的评论中指定的实例变量的类型。

int bo_id; 
NSString *bo_name; 
int bo_au_id; 
int bo_pub_id; 
int bo_num_pages; 
int bo_publish_year; 
NSString *bo_about; 
double bo_price; 
double bo_currency; 
NSString *bo_cover_img; 
double bo_recomended; 
int bo_sec_id; 
NSString *bo_path; 
int bo_sort; 

【问题讨论】:

  • 具体指的是哪一行?
  • 这一行:[cell setText:[NSString stringWithFormat:@"%d - %@ - %d - %d - %d - %d - %@ - %f - %f - %@ - %f - %d - %@ - %d",temp.bo_id, temp.bo_name, temp.bo_au_id, temp.bo_pub_id, temp.bo_num_pages, temp.bo_publish_year, temp.bo_about, temp.bo_price, temp.bo_currency, temp.bo_cover_img, temp.bo_recomended, temp.bo_sec_id, temp.bo_path, temp.bo_sort]];

标签: iphone objective-c ios exception


【解决方案1】:

setText 已弃用。而不是[cell setText:[NSString stringWithFormat:@"%d...,试试

cell.textLabel.text =[NSString stringWithFormat:@"%d...

错误可能在%d - %@ - %d - %d - %d - %d - %@ - %f - %f - %@ - %f - %d - %@ - %d 的长度范围内,导致参数不匹配 (NSInvalidArgumentException)。仔细浏览列表以找出错误。如果不查看各个元素的数据类型,就很难判断。

【讨论】:

  • 我这样做了,但它给了我一个带有线程 1 的 lldb:EXC_BAD_ACCESS (code =1, address= 0x53736902)
  • 你的映射是正确的!所以问题可能是对象self.books在设置文本之前在某处被释放(这可能是你在上面的评论中得到EXC_BAD_ACCESS的原因)。
【解决方案2】:

无法确定问题出在哪里,但几乎可以肯定,stringWithFormat: 中的参数与其格式说明符不匹配。

检查所有与%d 对应的东西实际上都是整数,而不是长整数或短整数。检查指定为 %@ 的东西是否真的是对象指针。此外,如果您在此处使用的任何类之前覆盖了 -description,请确保您没有在那里犯错。

实际错误是由将-isEqualToString: 发送到NSIndexSet 引起的,因此您可能在某个地方将NSIndexSet 视为字符串。

【讨论】:

  • 我不明白我到底应该做什么:(这是我的应用程序,请下载并检查它然后告诉我问题是什么..真的我需要帮助..mediafire.com/?ho5clejfwws3hue
  • @user1338832 抱歉,我没有时间修复其他人的应用程序中的错误。尝试在您的问题中发布Books 的界面作为初学者。
  • 应用中的界面,这里发不了
  • @user1338832 您不必发布整个界面,只需发布​​提到的类型,例如bo_idbo_name
  • int bo_id; NSString *bo_name; int bo_au_id; int bo_pub_id; int bo_num_pages; int bo_publish_year; NSString *bo_about;双bo_price;双 bo_currency; NSString *bo_cover_img;双博推荐; int bo_sec_id; NSString *bo_path; int bo_sort;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-21
  • 2017-02-01
  • 2021-01-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多