朋友们,我想让表视图数据与数组相互传递。
如果我们点击第一个表视图上的类别食物,它应该在第二个表视图上显示唯一行的条形图餐厅的详细选项,我不知道如何传递数据,请帮助,我可以如果需要,可以提供代码,并在需要时发送屏幕截图。
我需要这样的观点,请尽快帮助。
#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
答案 0 :(得分:0)
@john有两种方式可以像你想要的那样传递数据,1。您可以单独创建变量on以导航contraoller并使用segue方法2给出值。或者您可以使用键值传递数据 如果您想要更多细节而不是分享您的屏幕截图,那么您希望如何管理数据。