我正在编写应用程序,我创建了一个MainTableviewVontrolller.h
&带有相应目标文件的MainTableviewVontrolller.m
个文件,用于存储名为Youga.h
和Youga.m
的数据的Json
在上面这个MainTableviewVontrolller.m
我要从网络中提取一些数据,这是完美的。现在我要向另一个包含DetailTableViewController.h
&通过DetailTableViewController.m
在故事板上Showdetail
Segue,这里我要传递一些参数,因为我需要在我的数组中选择那些包含ycategoryName的索引等于早期MainTableviewVontrolller.m所选行的索引路径名{{ 1}}
我正在使用两种不同的网络服务
http://yoga.lifehealthinfo.com/api/yoga_list/categories,主键ID和姓名
http://yoga.lifehealthinfo.com/api/yoga_list/all,其中包含匹配的关键字类别yougaName
和category_id
category_name
现在查看2016-08-10 11:54:07.904 iYouga[622:21074] -[UITableViewController getCategory:]: unrecognized selector sent to instance 0x7fb195808490
2016-08-10 11:54:07.951 iYouga[622:21074] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewController getCategory:]: unrecognized selector sent to instance 0x7fb195808490'
*** First throw call stack:
(
0 CoreFoundation 0x0000000103933e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001033acdeb objc_exception_throw + 48
2 CoreFoundation 0x000000010393c48d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010388990a ___forwarding___ + 970
4 CoreFoundation 0x00000001038894b8 _CF_forwarding_prep_0 + 120
5 iYouga 0x0000000102ea90bf -[MainTableViewController prepareForSegue:sender:] + 351
6 UIKit 0x0000000104409f01 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 369
7 UIKit 0x0000000104409d5f -[UIStoryboardSegueTemplate _perform:] + 82
8 UIKit 0x000000010440a023 -[UIStoryboardSegueTemplate perform:] + 156
9 UIKit 0x0000000103e23cee -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1775
10 UIKit 0x0000000103e23fb3 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 388
11 UIKit 0x0000000103cec4a2 _runAfterCACommitDeferredBlocks + 317
12 UIKit 0x0000000103cffc01 _cleanUpAfterCAFlushAndRunDeferredBlocks + 95
13 UIKit 0x0000000103d0baf3 _afterCACommitHandler + 90
14 CoreFoundation 0x000000010385f367 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
15 CoreFoundation 0x000000010385f2d7 __CFRunLoopDoObservers + 391
16 CoreFoundation 0x0000000103854f2b __CFRunLoopRun + 1147
17 CoreFoundation 0x0000000103854828 CFRunLoopRunSpecific + 488
18 GraphicsServices 0x00000001070f0ad2 GSEventRunModal + 161
19 UIKit 0x0000000103ce0610 UIApplicationMain + 171
20 iYouga 0x0000000102ea98df main + 111
21 libdyld.dylib 0x000000010606f92d start + 1
22 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
文件
MainTableViewController.m
这是我的#import "MainTableViewController.h"
#import "Youga.h"
#import "DetailTableViewController.h"
#define getDataUrl @"http://yoga.lifehealthinfo.com/api/yoga_list/categories"
@interface MainTableViewController ()
@end
@implementation MainTableViewController
@synthesize jsonArray, yougaArray;
- (void)viewDidLoad {
[super viewDidLoad];
[self retrieveData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return yougaArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
Youga * YougaObject;
YougaObject = [yougaArray objectAtIndex:indexPath.row];
cell.textLabel.text = YougaObject.yougaName;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Configure the cell...
// Configure the cell...
return cell;
}
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
//get the object for selected row
Youga *object = [yougaArray objectAtIndex:indexPath.row];
[[segue destinationViewController] getCategory:object];
}}
-(void) retrieveData{
NSURL * url = [NSURL URLWithString:getDataUrl];
NSData * data = [NSData dataWithContentsOfURL:url];
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
NSDictionary *dataJSON = [jsonDict objectForKey:@"data"];
NSArray *allCategoriesJSON = [dataJSON objectForKey:@"categories"];
yougaArray = [[NSMutableArray alloc] init];
for (int i = 0; i < allCategoriesJSON.count; i ++)
{
NSDictionary *aCategoryJSON = [allCategoriesJSON objectAtIndex:i];
NSString *yId = [aCategoryJSON objectForKey:@"id"];
NSString *yName = [aCategoryJSON objectForKey:@"name"];
NSString *yDescription = [aCategoryJSON objectForKey:@"description"];
NSString *yImage = [aCategoryJSON objectForKey:@"image"];
[yougaArray addObject:[[Youga alloc] initWithYougaId:yId andYougaName:yName andYougaDescpription:yDescription andYougaImage:yImage]];
}
[self.tableView reloadData];
}
@end
文件
DetailTableViewController.m
有人能解决这个问题???