我是iOS开发人员的全新职位。我正在构建一个基本项目,我有两个视图控制器。在其中一个我有一个tableView,另一个我有一个标签和一个文本框。在tableview中,我使用了一个自定义单元格,并且已经采用了两个标签。在这两个标签中,我分配了两个数组。现在我想将两个数组的数据显示到另一个视图控制器的标签和文本字段。所以我想知道在didSelectRowAtIndexPath方法中写什么代码。如何在单击该特定单元格时将tableview单元格的数据显示给另一个viewcontroller?
这是我所做的代码。
#import "TabViewController.h"
@interface TabViewController()
@end
@implementation TabViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.peoplenames = @[@"Soumen Da" ,@"Debu Da" ,@"Sandipan Da" ,@"Pradipta Da" ,@"Sandeep Da" ,@"Pran Da" ,@"Amit Da" ,@"Piyali Di" ,@"Niladri Da" ,@"Biswa Da", @"Soumitra Da" ,@"Utpal Da", @"Sandip Da"];
self.peopleaddress = @[@"Santragachhi" ,@"Kolkata" ,@"Shambazar" ,@"Jadavpur" ,@"Saltlake" ,@"New Town" ,@"Beleghata" ,@"Garia" ,@"Barakpur" ,@"Naihati" ,@"Agarpara" ,@"Sodpur" ,@"Park Street"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
UILabel *lbl1 = (UILabel*)[cell.contentView viewWithTag:2];
lbl1.text = [self.peoplenames objectAtIndex:indexPath.row];
NSLog(@"row===%ld",(long)indexPath.row);
UILabel *lbl2 = (UILabel*)[cell.contentView viewWithTag:1];
lbl2.text = [self.peopleaddress objectAtIndex:indexPath.row];
NSLog(@"row===%ld",(long)indexPath.row);
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"detail" sender:self];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.peoplenames count];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
块引用
我是否需要为第二个视图控制器创建另一个类? – Tirthendu 2015-02-12 07:09:39
是的,您需要创建 – Arjuna 2015-02-12 07:58:00
非常感谢。一切都完成了。 – Tirthendu 2015-02-12 08:38:16