如何在viewController中从一个tableview移动到另一个tableview?
问题描述:
我有两个视图控制器(view1,view2),我添加了两个表视图(table1,table2),因为我想从第一个视图控制器的tableview移动到另一个视图控制器的表视图,在didSelectRowAtIndexPath。在厂景我有一个名为的getArray一个数组我想在这里显示这个阵列中的视图2(tableview2) 是我的代码 在视图2我创建了两个阵列如何在viewController中从一个tableview移动到另一个tableview?
NSMutableArray *getContestArray;
NSMutableArray * getContestIdArray;
UITableView *tableContest;
if (indexPath.row==0)
{
NSLog(@"Going to exam Id Class");
UIStoryboard *contestDetail =self.storyboard;
view2 *contestVC =[contestDetail instantiateViewControllerWithIdentifier:@"view2VC"];
[self presentViewController:contestVC animated:YES completion:nil];
}
else if (indexPath.row==1)
{
}
答
做如下事情,这只是给你基本的想法将数据从一个ViewController传输到另一个ViewController。根据您的要求修改以下代码。谢谢!
FirstViewController.h
@interface FirstViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
NSArray *getArray;
}
@property (strong, nonatomic) IBOutlet UITableView *tbl1;
FirstViewController.m
#import "SecondViewController.h"
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [getArray count];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
SecondViewController *objController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"]; //Give SecondViewController as identifier name to your SecondViewController from Storyboard
objController.array = [getArray objectAtIndex:indexPath.row];
[self.navigationController pushViewController:objController animated:YES];
}
SecondViewController.h
@interface SecondViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>
{
}
@property (strong, nonatomic) IBOutlet UITableView *tbl2;
@property (strong,nonatomic) NSArray *array;
SecondViewController.m
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [array count];
}
答
只是要在阵列中的视图2为这样的特性: -
@property NSMutableArray *arr2;
,并没有选择厂景的写代码 - >
SecondViewController *second=[self.storyboard instantiateViewControllerWithIdentifier:@"second"];
second.arr2=getArray;
[self.navigationController pushViewController:second animated:YES];