[英]how to call table data from one view controller to another via didselect row at indexpath method
I want to perform didselecterowatindexpath method please let me know how to call second viewcontroller from first view controller using below method and passing the data to other view controller : 我想执行didselecterowatindexpath方法,请让我知道如何使用以下方法从第一个视图控制器调用第二个视图控制器,并将数据传递给其他视图控制器:
My code is 我的代码是
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
pun=[tableData objectAtIndex:indexPath.row];
NSLog(@"PUN IS :%@",pun);
appDelegate.matri=pun;
NSLog(@"matriC:%@",appDelegate.matri);
SecViewController *SecView = [[SecViewController alloc] initWithNibName:@"SecViewController" bundle:nil];
[self.navigationController pushViewController:SecView animated:YES ];
Try this. 尝试这个。 its a best option.
这是一个最佳选择。 In your .h file create a method
在您的.h文件中创建一个方法
- (id)initWithNibName:(NSString *)nibNameOrNil Yourvariable:(yourdatatype *)variable Yourvariablex:(yourdatatype *)variablex bundle:(NSBundle *)nibBundleOrNil;
and in your .m file 并在您的.m文件中
- (id)initWithNibName:(NSString *)nibNameOrNil Yourvariable:(yourdatatype *)variable Yourvariablex:(yourdatatype *)variablex bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
//assign or use data here.
}
return self;
}
Hi Mate follow below steps : 您好伴侣,请按照以下步骤操作:
Goto SecViewController.h file and create a property of NSMutableArray. 转到SecViewController.h文件并创建NSMutableArray的属性。
@property(retain,nonatomic) NSMutableArray *newArray;
In tableView:didSelectRowAtIndexPath
method write 在
tableView:didSelectRowAtIndexPath
方法中写入
SecViewController *secView = [[SecViewController alloc] initWithNibName:@"SecViewController" bundle:nil]; secView.newArray = [tableData objectAtIndex:indexPath.row]; [self.navigationController pushViewController:secView animated:YES ];
In SecViewController print the below line in viewDidLoad
Method 在SecViewController中,在
viewDidLoad
方法中打印以下行
NSLog(@"%@",newArray);
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *tempString =[tableData objectAtIndex:indexPath.row];
NSLog(@"PUN IS :%@", tempString);
SecViewController *SecView = [[SecViewController alloc] initWithNibName:@"SecViewController" bundle:nil];
SecView.usernameString= tempString;
[self.navigationController pushViewController:SecView animated:YES ];
}
// .h file of SecViewController
#import <UIKit/UIKit.h>
@interface SecViewController : UIViewController
@property (nonatomic,strong) NSString *usernameString;
@end
// .m file of SecViewController
#import "ViewController.h"
@interface SecViewController ()
{
}
@end
@implementation SecViewController
@synthesize usernameString;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.