繁体   English   中英

iOS 7无法识别的选择器发送到带有按钮的实例问题

[英]IOS 7 unrecognized selector sent to instance issue with button

我有一个存储的JSON响应对象,如下所示:

ownerEvents = [NSMutableArray arrayWithArray:[(NSDictionary *)responseObject objectForKey:@"result"]];

ownerEvents将JSON存储在下面(通过xcode调试窗口检索):

2014-09-17 01:23:49.311 test123[31919:60b] JSON: {
result =     (
            {
        "end_time" = "4:00AM";
        "event_date" = "09-16-2014";
        "event_id" = 89;
        "event_image" = "http://www.jessetaveras.com/test123/images/event_flyers/event1141091689687507968f3f78ac5f23b2a954bb1dc6d.png";
        "event_price" = 30;
        "event_tickets_total" = 250;
        "event_title" = dfjjsnda;
        "start_time" = "5:00AM";
        "venue_name" = "the shit box";
        weekday = Tuesday;
    }{
        "end_time" = "4:00AM";
        "event_date" = "09-16-2014";
        "event_id" = 89;
        "event_image" = "http://www.jessetaveras.com/test123/images/event_flyers/event1141091689687507968f3f78ac5f23b2a954bb1dc6d.png";
        "event_price" = 30;
        "event_tickets_total" = 250;
        "event_title" = dfjjsnda;
        "start_time" = "5:00AM";
        "venue_name" = "the shit box";
        weekday = Tuesday;
    }
);
}

然后,上面的JSON在表格视图中分为2个不同的单元格

我需要将单个单元格的数据发送到另一个视图控制器。 在应该将数据发送到另一个视图控制器的函数中,我有以下代码:

在单元格类中,我有:

@property (strong, nonatomic) IBOutlet UIButton *editButtonPressed;

在CellForRowAtIndexPath(在UIViewController中)中,我有:

- (UITableViewCell *)tableView:(UITableView *)tableView   cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"OwnerCell";

TDOwnerViewCell *historyCell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier ];
historyCell.selectionStyle =  UITableViewCellSelectionStyleNone;
//NSLog(@"THIS IS current Cell %@", [ownerEvents  objectAtIndex:indexPath.row]);

[historyCell configOwnerEventCell:[ownerEvents objectAtIndex:indexPath.row]];

[historyCell.editButtonPressed addTarget:self action:@selector(editButtonPressed)  forControlEvents:UIControlEventTouchUpInside];
historyCell.editButtonPressed.tag = indexPath.row;
if(historyCell == nil)
{
historyCell = [[TDOwnerViewCell alloc]  initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:@"OwnerCell"];
}
return historyCell;    
}

这是按下按钮时要调用的方法:

- (void)editButtonPressed:(UIButton *) button{
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];

TDEventEditViewController * vc3 = [storyboard instantiateViewControllerWithIdentifier:@"eventEditView"];

[historyCell configOwnerEventCell:[ownerEvents objectAtIndex:indexPath.row]];
NSInteger index = button.tag;

NSArray *eventsJSONData = [ownerEvents objectAtIndex:index];
ownerEvents = [NSMutableArray arrayWithArray:[(NSDictionary *)responseObject objectForKey:@"result"]];

vc3.detailDic = eventsJSONData[index];

[self.navigationController pushViewController:vc3 animated:YES];
}

我收到此错误:

-[TDOwnerViewCell editButtonPressed:]: unrecognized        selector sent to instance 0xca00000
2014-09-17 01:46:21.884 test123[31919:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException',  reason: '-[TDOwnerViewCell editButtonPressed:]: unrecognized  selector sent to instance 0xca00000'
*** First throw call stack:
(
0   CoreFoundation                      0x034391e4   __exceptionPreprocess + 180
1   libobjc.A.dylib                     0x031b88e5  objc_exception_throw + 44
2   CoreFoundation                      0x034d6243 - [NSObject(NSObject) doesNotRecognizeSelector:] + 275
3   CoreFoundation                      0x0342950b  ___forwarding___ + 1019
4   CoreFoundation                      0x034290ee  _CF_forwarding_prep_0 + 14
5   libobjc.A.dylib                     0x031ca880 - [NSObject performSelector:withObject:withObject:] + 77
6   UIKit                               0x01e7a3b9 - [UIApplication sendAction:to:from:forEvent:] + 108
7   UIKit                               0x01e7a345 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
8   UIKit                               0x01f7bbd1 -[UIControl sendAction:to:forEvent:] + 66
9   UIKit                               0x01f7bfc6 -[UIControl _sendActionsForEvents:withEvent:] + 577
10  UIKit                               0x01f7b243 -[UIControl touchesEnded:withEvent:] + 641
11  UIKit                               0x022102e3 _UIGestureRecognizerUpdate + 7166
12  UIKit                               0x01eb9a5a -[UIWindow _sendGesturesForEvent:] + 1291
13  UIKit                               0x01eba971 -[UIWindow sendEvent:] + 1021
14  UIKit                               0x01e8c5f2 -[UIApplication sendEvent:] + 242
15  UIKit                               0x01e76353 _UIApplicationHandleEventQueue + 11455
16  CoreFoundation                      0x033c277f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
17  CoreFoundation                      0x033c210b __CFRunLoopDoSources0 + 235
18  CoreFoundation                      0x033df1ae __CFRunLoopRun + 910
19  CoreFoundation                      0x033de9d3 CFRunLoopRunSpecific + 467
20  CoreFoundation                      0x033de7eb CFRunLoopRunInMode + 123
21  GraphicsServices                    0x04c475ee GSEventRunModal + 192
22  GraphicsServices                    0x04c4742b GSEventRun + 104
23  UIKit                               0x01e78f9b UIApplicationMain + 1225
24  test123                               0x000e3f9d main + 141
25  libdyld.dylib                       0x039b6701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of  type NSException
(lldb) 

请帮助,我似乎从来没有弄清楚这些错误。 提前致谢。

在您的情节提要中,editButtonPressed方法可能与其他方法连接在一起,只需转到您的情节提要,然后使用该方法检查按钮的连接

您调用此editButtonPressed方法,该方法未连接或在您的逻辑中不存在。

-[TDOwnerViewCell editButtonPressed:]: unrecognized        selector sent to instance 0xca00000
2014-09-17 01:46:21.884 test123[31919:60b] *** Terminating app due to uncaught exception     'NSInvalidArgumentException',  reason: '-[TDOwnerViewCell editButtonPressed:]: unrecognized      selector sent to instance 0xca00000'

因此,您能否共享您的用于在VC之间传递数据的方法。

更新:-首先,如下更改cellForRowAtIndexPath方法中的流。

- (UITableViewCell *)tableView:(UITableView *)tableView   cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"OwnerCell";

  TDOwnerViewCell *historyCell = [tableView  dequeueReusableCellWithIdentifier:CellIdentifier ];

  //You need to check if historyCell is nil or not firstly then move on to your further populating logic.
  if(historyCell == nil)
  {
      historyCell = [[TDOwnerViewCell alloc]  initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:@"OwnerCell"];
  }

  historyCell.selectionStyle =  UITableViewCellSelectionStyleNone;

  [historyCell configOwnerEventCell:[ownerEvents objectAtIndex:indexPath.row]];

  [historyCell.editButtonPressed addTarget:self action:@selector(editButtonPressed)  forControlEvents:UIControlEventTouchUpInside];
  historyCell.editButtonPressed.tag = indexPath.row;

  return historyCell;    
}

在您的情况下,问题可能是,当您检查historyCell是否为nil或未在末尾时,以防万一它为nil,然后返回了一个新的历史单元格。

所以尝试一下,让我知道是否有任何问题。

我将设置一个断点并逐步执行,确保一切都按照您的想法进行了初始化。

例如,这实际上是否被填充?

NSArray *eventsJSONData = [ownerEvents  objectAtIndex:index];

再次,这实际上被填充吗?

vc3.detailDic = eventsJSONData[index];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM