顯示我使用泰伯維顯示名稱從recipes Array
其中工程從recipes Array
表視圖很大,並顯示所有名稱多行。當我點擊其中一個配方時,它會在詳細視圖中顯示名稱。表視圖細胞 - 的UITableView - 不能在詳細視圖
我被卡住的是如何顯示其他字段在detailed view
。我有一個數組(array name: ingredients
),其中包含具體配方的內容,例如成分。
我
cell.textLabel.text = [ingredients objectAtIndex:indexPath.row];
試圖RecipeDetailViewController.h
#import <UIKit/UIKit.h>
@interface RecipeDetailViewController : UIViewController
@property (nonatomic, strong) IBOutlet UILabel *recipeLabel;
@property (nonatomic, strong) NSString *recipeName;
@property (strong, nonatomic) IBOutlet UILabel *recipeCountry;
@property (nonatomic, strong) NSString *recipeCountryName;
@end
,但它並沒有顯示在RecipeBookViewController.m 什麼這是我的原代碼
#import "RecipeBookViewController.h"
#import "RecipeDetailViewController.h"
@interface RecipeBookViewController()
@end
@implementation RecipeBookViewController {
NSArray *recipes;
}
@synthesize tableView;
- (void)viewDidLoad
{
[super viewDidLoad];
NSData *allCourseData=[[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://api.kivaws.org/v1/loans/search.json?status=fundraising"]];
NSError *error;
NSMutableDictionary *JsonObject = [NSJSONSerialization
JSONObjectWithData:allCourseData options:NSJSONReadingMutableContainers
error:&error];
NSArray *loans = JsonObject[@"loans"];
// Create a new loans array for store the new items
NSMutableArray *newLoans = [NSMutableArray array];
NSMutableArray *arrCountry = [NSMutableArray array];
for (NSDictionary *loan in loans) {
NSNumber *ident = loan[@"id"];
NSString *name = loan[@"name"];
NSDictionary *description = loan[@"description"];
NSDictionary *location = loan[@"location"];
NSString *country = location[@"country"];
NSString *status = loan[@"status"];
NSDictionary *geo = location[@"geo"];
NSString *geoprint = geo[@"pairs"];
[newLoans addObject:name];
[arrCountry addObject:country];
}
recipes=newLoans;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [recipes count];
}
//Display Name in Detail View
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"RecipeCell";
//Displays name
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [recipes objectAtIndex:indexPath.row];
return cell;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
RecipeDetailViewController *destViewController = segue.destinationViewController;
destViewController.recipeName = [recipes objectAtIndex:indexPath.row];
}
}
@end
RecipeDetailViewController.m
#import "RecipeDetailViewController.h"
@interface RecipeDetailViewController()
@end
@implementation RecipeDetailViewController
@synthesize recipeLabel;
@synthesize recipeName;
@synthesize recipeCountry;
@synthesize recipeCountryName;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Set the Label text with the selected recipe
recipeLabel.text = recipeName;
recipeCountry.text=recipeCountryName;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
這裏有兩種觀點
您需要向我們顯示顯示詳細視圖的代碼。 – deadbeef
@deadbeef我爲RecipeDetailViewController.m添加了代碼 – user580950
顯示您在哪裏導航到RecipeDetailVIewController並顯示您的主/成分數組數據。 – Shoaib