Ios 如何使用NSdictionary填充数据?
如何将数据发送到另一个详图视图控制器中的表视图?在我的第一张桌子上,我没有得到预期的输出。现在我需要用具有属性detailContent的数据填充第二个表。这是我的密码Ios 如何使用NSdictionary填充数据?,ios,uiviewcontroller,nsarray,nsdictionary,Ios,Uiviewcontroller,Nsarray,Nsdictionary,如何将数据发送到另一个详图视图控制器中的表视图?在我的第一张桌子上,我没有得到预期的输出。现在我需要用具有属性detailContent的数据填充第二个表。这是我的密码 #import <UIKit/UIKit.h> @interface RecipeBookViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> @property (nonatomic, stro
#import <UIKit/UIKit.h>
@interface RecipeBookViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) IBOutlet UITableView *tableView;
@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 "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
#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
要填充下一个tableView,需要实现UITableView委托和协议方法 在RecipedDetailViewController中
实施:
@interface RecipeDetailViewController () <UItableViewDataSource, UITableViewDelegate>
@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);
}
- (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;
}
@结束
返回RecipeBookViewController.m
in PrepareForSegue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
RecipeDetailViewController *destViewController = segue.destinationViewController;
destViewController.recipe = recipe;
}
}
费萨尔,到底是什么问题?您是否能够按下viewController,或者您在下一个视图中看不到数据的问题?先生,我想填充第二个表。若我在第一个表中单击了veg,那个么我应该会在详细视图表中看到veg列表,如(chappathi、rotti等)。如果(鸡、羊肉等)是那样的话。我不知道在哪里和如何申报这个。你能帮忙吗?请……这对我作为新生会更有帮助。所以,现在你在下一个viewController上看不到蔬菜了,对吗?如果答案是肯定的,那么您是否检查了出口?destViewController.recipeName=[recipes objectAtIndex:indexPath.row];destViewController.detailContent=[recipes objectAtIndex:indexPath.row];->将同一字符串两次传递给第二个VC。一本不应该是详细的词典吗?我在任何地方都看不到NSDictionary…@Basheer_CAD:我在第二个控制器中看到了veg标签,我在第二个表中也有一个表视图。现在我想使用NSDictionary在表中填充veg、NOVEG和饮料数据!谢谢你的帮助,先生。现在我需要在单击veg时填充chappathi、rotti等数据。在点击其他类似的项目时。。先生,我有一个“vegDict=[[NSMutableDictionary alloc]initWithObjectsAndKeys:@“Rotti”,“Chappathi”,nil]在详细视图中;“现在我如何传递这些数据?”?同样在我的CelforRowatineXpath中,我有“cell.textLabel.text=[vegDict objectForKey:vegDict];”请解释如何将vegDict传递到第二个表IR,我有同一个表的更新代码。你能帮我查一下产量吗?
in PrepareForSegue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showRecipeDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
RecipeDetailViewController *destViewController = segue.destinationViewController;
destViewController.recipe = recipe;
}
}