简体   繁体   English

如何通过索引路径方法中的didselect行从一个视图控制器调用表数据到另一个视图控制器

[英]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 : 您好伴侣,请按照以下步骤操作:

  1. Goto SecViewController.h file and create a property of NSMutableArray. 转到SecViewController.h文件并创建NSMutableArray的属性。

    @property(retain,nonatomic) NSMutableArray *newArray;

  2. 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 ];

  3. 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.

相关问题 Swift:如何获取表行单元格(indexPath)并从详细视图控制器的数据模型中加载它? - Swift: How to get the table row cell (indexPath) and load it from the data model in detail view controller? 如何在另一个视图中调用indexPath? - How to call indexPath in another view? 如何从另一个视图控制器调用方法 - How to call a method from another view controller Swift 4.2-如何从tableView中的“ didSelectRowAtIndexPath”方法调用“ indexPath.row”到另一个类? - Swift 4.2 - How to call “indexPath.row” from “didSelectRowAtIndexPath” method in a tableView to another class? 在选择表格单元格“ didSelect”时,如何将图像解析到另一个视图? - On selecting the table cell “didSelect” how to parse images to another View? 如何在一个视图控制器上使用按钮将文本添加到另一个视图控制器的表视图中的行? - How can I use a button on one view controller to add text to a row in a table view in another view controller? 如何从另一个视图控制器调用方法 - How do I call a method from another view controller 是否可以调用另一个视图控制器的tableview didSelect索引路径并执行它? - Is it possible to call another view controller's tableview didSelect index path and execute it? 从集合视图和表视图didselect从第一视图推送的呼叫的第二视图的viewdidload花费的时间 - viewdidload of second view taking time for call that is push from first view by collection view & table view didselect 如何在IOS中将数据从一个视图传递到另一个视图控制器? - How to pass data from one view to another view controller in IOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM