我是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