简体   繁体   中英

IOS 7 unrecognized selector sent to instance issue with button

I have a JSON response object that is stored as shown below:

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

ownerEvents stores the JSON below (retrieved via xcode debug window):

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;
    }
);
}

The JSON above is then split into 2 different cells in a table view

I need to send the data of an individual cell to another view controller. Inside the function that is supposed to send the data to the other view controller I have this code:

within the cell class I have:

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

within CellForRowAtIndexPath (which is in a UIViewController) I have:

- (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;    
}

This is the method being called when the button is pressed:

- (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];
}

I am getting this error:

-[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) 

Please help, I never seem to figure these errors out. Thanks in advance.

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

Your calling this editButtonPressed method which is not connected or present in your logic.

-[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'

So could u share your method used for passing data between your VC's.

Update :- Firstly, change flow in cellForRowAtIndexPath method as below.

- (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;    
}

In your case, issue might be that as u were checking for historyCell is nil or not at end then as in case it was nil then a new history cell was returned.

So try out this and let me know if any issue.

I would set a break point and step through each bit, make sure everything is initialised with what you think it is.

For instance, does this actually get populated?

NSArray *eventsJSONData = [ownerEvents  objectAtIndex:index];

Again, does this actually get populated?

vc3.detailDic = eventsJSONData[index];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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