我有一个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)
请帮助,我似乎从未想过这些错误。提前谢谢。
答案 0 :(得分:0)
editButtonPressed方法可能与故事板中的不同方法相关联,只需转到故事板并使用方法检查按钮的连接
答案 1 :(得分:0)
您调用此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然后返回了新的历史单元格。
所以试试这个并告诉我是否有任何问题。
答案 2 :(得分:-1)
我会设置一个断点并逐步完成每一位,确保所有内容都按照您的想法进行初始化。
例如,这实际上是否已填充?
NSArray *eventsJSONData = [ownerEvents objectAtIndex:index];
再次,这实际上是否已填充?
vc3.detailDic = eventsJSONData[index];