- [用户长度]:无法识别的选择器发送到实例0x7fc7b60143e0'

时间:2014-11-30 02:12:49

标签: ios nsmutablearray

我有以下代码并收到标题中指示的错误代码: 这是我发送给User对象的唯一消息(除了使用" new"初始化它) 当我发表评论addObject时:它并没有抱怨。 有人可以帮忙吗?谢谢!

self.freshUser.name = self.name.text;
self.freshUser.age = (int)self.age.text;
self.freshUser.gender = self.gender.text;

//NSLog(@"%@",[NSThread callStackSymbols]);
[appDelegate.users addObject:self.freshUser];

(我的用户对象是NSObject的子类。它有更多我不能使用的属性。只是一些额外的信息)

-(UITableViewCell *)tableView:(UITableView *)tableViewPara cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  UserCell *cell = [tableViewPara dequeueReusableCellWithIdentifier:usersTableIdentifier forIndexPath:indexPath];

  if(indexPath.row == [appDelegate.users count]){
    cell.nameLabel.text = @"+";
    cell.nameLabel.font = [UIFont systemFontOfSize:36];
    cell.bgImg.image = [UIImage imageNamed:@"background_gray"];
    cell.statusImg.image = nil;
  }else{
    cell.nameLabel.text = appDelegate.users[indexPath.row];
    cell.nameLabel.font = [UIFont systemFontOfSize:17];
    cell.bgImg.image = [UIImage imageNamed:@"background_dark_red"];
    cell.statusImg.image = [UIImage imageNamed:@"icon_cloud"];
  }
  cell.nameLabel.textAlignment = NSTextAlignmentCenter;
  cell.nameLabel.textColor = [UIColor whiteColor];
  cell.nameLabel.backgroundColor = [UIColor clearColor];

  return cell;
}

空间

0   CoreFoundation                      0x000000010ff1bf35 __exceptionPreprocess + 165
1   libobjc.A.dylib                     0x000000010fbb4bb7 objc_exception_throw + 45
2   CoreFoundation                      0x000000010ff2304d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x000000010fe7b27c ___forwarding___ + 988
4   CoreFoundation                      0x000000010fe7ae18 _CF_forwarding_prep_0 + 120
5   UIKit                               0x00000001104d034b -[UILabel _setFont:] + 101
6   Raymio                              0x000000010f67857f -[StartViewController tableView:cellForRowAtIndexPath:] + 991
7   UIKit                               0x00000001103ff4b3 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 508
8   UIKit                               0x00000001103defb1 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2846
9   UIKit                               0x00000001103f4e3c -[UITableView layoutSubviews] + 213
10  UIKit                               0x0000000110381973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
11  QuartzCore                          0x0000000113c09de8 -[CALayer layoutSublayers] + 150
12  QuartzCore                          0x0000000113bfea0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
13  QuartzCore                          0x0000000113bfe87e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
14  QuartzCore                          0x0000000113b6c63e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
15  QuartzCore                          0x0000000113b6d74a _ZN2CA11Transaction6commitEv + 390
16  QuartzCore                          0x0000000113b6ddb5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
17  CoreFoundation                      0x000000010fe50dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
18  CoreFoundation                      0x000000010fe50d20 __CFRunLoopDoObservers + 368
19  CoreFoundation                      0x000000010fe46b53 __CFRunLoopRun + 1123
20  CoreFoundation                      0x000000010fe46486 CFRunLoopRunSpecific + 470
21  GraphicsServices                    0x00000001134fd9f0 GSEventRunModal + 161
22  UIKit                               0x0000000110308420 UIApplicationMain + 1282
23  Raymio                              0x000000010f678a83 main + 115
24  libdyld.dylib                       0x00000001124ab145 start + 1

2 个答案:

答案 0 :(得分:1)

这一行:

cell.nameLabel.text = appDelegate.users[indexPath.row];

您正在尝试将User对象设置为标签字段的文本。那不行。你会想要这个或类似的东西:

cell.nameLabel.text = ((User *)appDelegate.users[indexPath.row]).name;

答案 1 :(得分:0)

您与我们分享了您的堆栈跟踪。一个有用的技术是查看引用您编写的代码的任何内容。您可能会注意到第6行引用了您的StartViewController

6   Raymio                              0x000000010f67857f -[StartViewController tableView:cellForRowAtIndexPath:] + 991

您可以通过在第三列中使用该地址键入source list命令来显示相关的代码行:

(lldb) source list -a 0x000000010f67857f

   43        cell.nameLabel.text = @"+";
   44        cell.nameLabel.font = [UIFont systemFontOfSize:36];
   45        cell.bgImg.image = [UIImage imageNamed:@"background_gray"];
   46        cell.statusImg.image = nil;
   47      }else{
-> 48        cell.nameLabel.text = appDelegate.users[indexPath.row];
   49        cell.nameLabel.font = [UIFont systemFontOfSize:17];
   50        cell.bgImg.image = [UIImage imageNamed:@"background_dark_red"];
   51        cell.statusImg.image = [UIImage imageNamed:@"icon_cloud"];
   52      }

显然,您的行号和内存地址会有所不同,但希望这可以说明这个想法。扫描堆栈跟踪以查找引用您的代码的任何内容,并检查该行代码是否存在任何潜在问题。

顺便说一句,this discussion。还向您展示了如何使用堆栈跟踪的-[StartViewController tableView:cellForRowAtIndexPath:] + 991来显示相关的代码行。