我不太擅长编码,我的代码有一个严重的问题,我想将我的 json 数据从一个表显示到另一个表,例如:在第一个表视图中我想显示学生的名字,名字之后是点击后,它将跳转到下一个 tableview 并显示该学生已选择的课程(一个学生可能有多个课程),那么我该怎么做呢?这是第一个 tableview 中的 mycode
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
self.navigationItem.Title = @"選擇類別";
// classify = [[NSArray alloc] initWithObjects: @"時尚類",@"飲食類",@"娛樂類",@"文創類", nil];
// NSString *path = [[NSBundle mainBundle] pathForResource:@"DataList" ofType:@"plist"];
// classify_ = [[NSMutableArray alloc] initWithContentsOfFile : path];
NSURL *url = [NSURL URLWithString:@"http://localhost/store.php"];
NSData *jsonData=[NSData dataWithContentsOfURL:url];
NSError *error = nil;
classify_ = [NSJSONSerialization JSONObjectWithData:jsonData options:
NSJSONReadingMutableContainers error:&error];
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
//table cell count
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.classify count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.textLabel.text = [[self.classify objectAtIndex:indexPath.row] objectForKey:@"classify"];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure your segue name in storyboard is the same as this line
if ([[segue identifier] isEqualToString:@"Second"])
{
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
//NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[[segue destinationViewController] setSecondClassify:[self.classify objectAtIndex:indexPath.row]];
}
}