Table 查看数据通过数组传递

Table view data pass with arrays

朋友们,我想让table视图数据通过数组相互传递。

如果我们在第一个 table 视图中单击类别食物,它应该在第二个 table 视图中以唯一行显示酒吧餐厅的详细信息选项,我不知道如何在之间传递数据,请帮忙,如果你愿意,我可以提供代码,如果需要,我可以发送屏幕截图。

我需要这样的视图,请尽快帮助。

#import "categoryViewController.h"

@interface categoryViewController ()<UITableViewDelegate,UITableViewDataSource>
{
NSArray *tableData,*thumbNails;
}
@property (weak,nonatomic) IBOutlet UITableView *categoryTable;
@property (weak,nonatomic) NSArray *tabledata;
@end

@implementation categoryViewController

- (void)viewDidLoad {

    tableData = [[NSArray alloc]initWithObjects:@"Food and Drinks",@"Shopping",@"Housing",@"Transportation",@"Vehicle",@"Life and Entertainment",@"Communication & PC",@"Financial Expenses",@"Investment",@"Income",@"Others",nil];

//thumbnails=[[NSArray alloc]initWithObjects:@"Food and Drinks.png"@"Shopping.png",@"Shopping.png",@"Shopping.png",@"Shopping.png",@"Shopping.png",@"Shopping.png",@"Shopping.png",@"Shopping.png",@"Shopping.png",@"Shopping.png", nil];

[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:  (NSInteger)section
{
return tableData.count;
}

 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{   //Updated method to go to the next View.
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"Cell"];

    if (cell==nil) {
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
    //outdated method.
  //  UITableViewCell *cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];

    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    //cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
    // work on ittttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt.

    return cell;
    }
    /*
    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
NSIndexPath *index = [self.categoryTable indexPathForSelectedRow];
subcategoryViewController *scVC = [segue destinationViewController];
}
*/
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(IBAction)backBtn:(id)sender{
    [self dismissViewControllerAnimated:YES completion:nil];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

@john 有两种方法可以按照您想要的方式传递数据,1。您可以单独创建变量以导航控制器并在 segue 方法 2 中给它们赋值。或者您可以使用键值传递数据 如果您想要比分享您的屏幕截图更详细的信息,您希望如何管理您的数据。