UITableViewCell 遇到问题
我正在使用新的 iOS5 TableView 样式代码,但我似乎遇到了问题。每当调用 Searching = true 函数时,它都会崩溃。我认为尝试将 UITableView 对象传递给接受 BadgedCell 的配置方法。有什么想法如何解决这个问题吗?
Crash says: 2011-10-25 22:21:04.973 Social[5719:707] -[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x392510
2011-10-25 22:21:04.975 Social[5719:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x392510'
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(searching)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SearchCell"];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
else
{
TDBadgedCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BadgedCell"];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
}
- (void)configureCell:(TDBadgedCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
if(searching)
{
NSDictionary *dictionary = (NSDictionary *)[listOfItems objectAtIndex:indexPath.row];
[cell.textLabel setText:[dictionary objectForKey:@"exerciseName"]];
[cell.detailTextLabel setText:[dictionary objectForKey:@"muscleName"]];
cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [listOfItems objectAtIndex:indexPath.row];
}
else
{
cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16];
cell.textLabel.text = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"muscleName"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
I'm using the new iOS5 TableView style code, but I seem to get a problem. It crashes whenever the searching = true function is called. I think it is triyng to pass the UITableView Object to the configure method with accepts the BadgedCell. Any ideas how to fix this?
Crash says: 2011-10-25 22:21:04.973 Social[5719:707] -[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x392510
2011-10-25 22:21:04.975 Social[5719:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary isEqualToString:]: unrecognized selector sent to instance 0x392510'
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(searching)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SearchCell"];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
else
{
TDBadgedCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BadgedCell"];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
}
- (void)configureCell:(TDBadgedCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
if(searching)
{
NSDictionary *dictionary = (NSDictionary *)[listOfItems objectAtIndex:indexPath.row];
[cell.textLabel setText:[dictionary objectForKey:@"exerciseName"]];
[cell.detailTextLabel setText:[dictionary objectForKey:@"muscleName"]];
cell.textLabel.text = [listOfItems objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [listOfItems objectAtIndex:indexPath.row];
}
else
{
cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:16];
cell.textLabel.text = [[self.muscleArray objectAtIndex:indexPath.row]objectForKey:@"muscleName"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将 listOfItems 字典作为字符串传递到单元格:
如果您使用此:
我知道 listOfItems 包含许多字典。
因此,当您调用时:
您基本上是在尝试将字典分配给单元格标签。这就是为什么 Xcode 告诉你 [__NSCFDictionary isEqualToString:]。
尝试删除这些行。
You are passing the listOfItems dictionary as a string to the cell:
If you used this:
I understand that listOfItems contains many dictionaries.
So when you call:
You are basically trying to assign a dictionary to a cell label. thats why Xcode is telling you that [__NSCFDictionary isEqualToString:].
try to remove those lines.
您需要从配置方法中删除这两行,因为如果如前面三行所暗示的那样,您的“listOfItems”是一个字典列表,那么您尝试将字典设置为 textLabel 的文本字段,这将导致所有各种各样的问题。
You need to remove these two lines from inside your configure method, because if as the preceding three lines imply, your 'listOfItems' is a list of dictionaries then you are trying to set a dictionary as the text field of a textLabel which will cause all sorts of problems.