iam不是很好的編碼,我有一個嚴重的問題在我的代碼中,我想顯示我的json數據從一個talbe到另一個,例如:在第一個tableview中,我想顯示學生「名稱,點擊名稱後,它將跳轉到下一個tableview並顯示該學生選擇的課程(一個學生可能有多個課程),那麼我該怎麼做呢?以下是mycode實現代碼如下JSON數據UITableView到UITableView
- (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]];
}
}
你是來自臺灣或香港? –
順便提一下,您的問題與JSON無關。一旦你的數據在'classify'數組中,它可能來自任何地方。 –