Reputation: 162
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 :
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 ];
Upvotes: 0
Views: 339
Reputation: 849
Hi Mate follow below steps :
Goto SecViewController.h file and create a property of NSMutableArray.
@property(retain,nonatomic) NSMutableArray *newArray;
In tableView:didSelectRowAtIndexPath
method write
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
NSLog(@"%@",newArray);
Upvotes: 0
Reputation: 1847
Try this. its a best option. In your .h file create a method
- (id)initWithNibName:(NSString *)nibNameOrNil Yourvariable:(yourdatatype *)variable Yourvariablex:(yourdatatype *)variablex bundle:(NSBundle *)nibBundleOrNil;
and in your .m file
- (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;
}
Upvotes: 1
Reputation: 1097
-(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;
Upvotes: 0