我想执行didselecterowatindexpath方法请让我知道如何使用以下方法从第一个视图控制器调用第二个viewcontroller并将数据传递给其他视图控制器:
我的代码是
-(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 ];
答案 0 :(得分:1)
试试这个。这是一个最好的选择。 在.h文件中创建方法
- (id)initWithNibName:(NSString *)nibNameOrNil Yourvariable:(yourdatatype *)variable Yourvariablex:(yourdatatype *)variablex bundle:(NSBundle *)nibBundleOrNil;
并在您的.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;
}
答案 1 :(得分:0)
嗨Mate按照以下步骤操作:
转到SecViewController.h文件并创建NSMutableArray的属性。
@property(retain,nonatomic) NSMutableArray *newArray;
在tableView:didSelectRowAtIndexPath
方法中写
SecViewController *secView = [[SecViewController alloc] initWithNibName:@"SecViewController" bundle:nil];
secView.newArray = [tableData objectAtIndex:indexPath.row];
[self.navigationController pushViewController:secView animated:YES ];
在SecViewController中,在viewDidLoad
方法
NSLog(@"%@",newArray);
答案 2 :(得分:0)
-(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;