如何将数据发送到另一个详细视图控制器的表视图?在我的第一张桌子上,我没有得到我的预期输出。现在我需要使用具有属性detailContent的数据填充我的第二个表。这是我的代码。如何使用NSdictionary填充数据?
#import <UIKit/UIKit.h>
@interface RecipeBookViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) IBOutlet UITableView *tableView;
@end``
\在执行:
#import "RecipeBookViewController.h"
#import "RecipeDetailViewController.h"
@interface RecipeBookViewController()
@end
@implementation RecipeBookViewController {
NSArray *recipes;
}
@synthesize tableView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Initialize table data
recipes = [NSArray arrayWithObjects:@"Veg", @"Non Veg", @"Beverages", nil];
}
- (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];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"RecipeCell";
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];
destViewController.detailContent = [recipes objectAtIndex:indexPath.row];
}
}
@end
\详细视图:
@interface RecipeDetailViewController : UIViewController
@property (nonatomic, strong) IBOutlet UILabel *recipeLabel;
@property (nonatomic, strong) NSString *recipeName;
@property (nonatomic , strong)NSString *recipeTable ;
@property (nonatomic , strong) IBOutlet UITableView *detailContent ;
@end
在执行:
#import "RecipeDetailViewController.h"
@interface RecipeDetailViewController()
@end
@implementation RecipeDetailViewController
@synthesize recipeLabel;
@synthesize recipeName;
- (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;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
费萨尔,究竟是什么的问题?你能推动viewController,或者你没有看到你的数据在下一个视图的问题? –
我想填充第二个表格先生。如果在第一个表格中点击veg,那么我应该在详细视图表中看到像(chappathi,rotti等)的veg列表。如果不是这样(鸡肉,羊肉等)。我不知道在哪里以及如何申报这一个。你能帮忙吗?PLS作为新鲜 –
所以,现在你看不到下一个的viewController的蔬菜,正确的..它会为我更有帮助?如果答案是肯定的,那么你是否检查你的网点? –