Ios 单元格选择并将其数据传输到另一个tableview

Ios 单元格选择并将其数据传输到另一个tableview,ios,objective-c,Ios,Objective C,请某人, 我有两个桌面视图。 在tv1中,您可以创建单元格,然后这些单元格与另一个vc相连,在那里您可以看到单元格的详细信息。 在2tv中,我在NavitaionControl中有一个按钮,(+),它打开了Tv1。 我想做的是从tv1点击单元格,然后将数据单元格传输到tv2 我做不到 我使用了以下功能: - (Void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath

请某人,
我有两个桌面视图。
在tv1中,您可以创建单元格,然后这些单元格与另一个vc相连,在那里您可以看到单元格的详细信息。
在2tv中,我在NavitaionControl中有一个按钮,(+),它打开了Tv1。
我想做的是从tv1点击单元格,然后将数据单元格传输到tv2
我做不到

我使用了以下功能:

- (Void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath
我把它放在VC1中,它的代码是:

- (Void) tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath
{
    if ([self.getFromManagerWorkerViewController isEqualToString: @ "yes"])
    {
        NSManagedObject * Workers = [self.Workers objectAtIndex: indexPath.row];
        ManagerWorker * m = [[ManagerWorker alloc] init];
        
        
        m.ListWorkerArray = [[NSMutableArray alloc] initWithObjects: [Workers valueForKey: @ "lastname"], [Workers valueForKey: @ "firstname"], [Workers valueForKey: @ "title"], [Workers valueForKey: @ "image"] , nil];
        
        self.getFromManagerWorkerViewController = [NSMutableString stringWithFormat: @ "no"];
        [self.navigationController popViewControllerAnimated: YES];
}
如您所见,我在Vc2中有一个名为ListWorker的数组
所有我需要的信息,我选择进入系统。
但是当函数结束时,留下了空数组,并且不清楚为什么


我正在使用核心数据…

尝试为tv1编写一个委托,该委托将通过didSelectRowAtIndexPath方法传递单元格:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ...code...
    if(isOpenFromDetailVC) {
        [self.delegate tableView:tableView wantsToPassCell:cell];
    }
    ...code...
}
只需记住将detailVC甚至tv2设置为tv1的代理。然后在协议的实现方法中,尝试将小区添加到tv2中

您可以尝试这样做,例如,将单元格添加到协议实现方法中的数组中,然后将它们加载到cellForRowAtIndexPath方法中的Tv2int中

如果您不认识学员,请查看apple文档和本主题:

以下是链接下显示的示例:

简单的例子

假设子视图控制器有一个UISlider,我们想通过 滑块的值通过委托返回给父对象

在子视图控制器的头文件中,声明委托类型 及其方法:

ChildViewController.h

#import <UIKit/UIKit.h>

// 1. Forward declaration of ChildViewControllerDelegate - this just declares
// that a ChildViewControllerDelegate type exists so that we can use it
// later.
@protocol ChildViewControllerDelegate;

// 2. Declaration of the view controller class, as usual
@interface ChildViewController : UIViewController

// Delegate properties should always be weak references
// See https://stackoverflow.com/a/4796131/263871 for the rationale
// (Tip: If you're not using ARC, use `assign` instead of `weak`)
@property (nonatomic, weak) id<ChildViewControllerDelegate> delegate;

// A simple IBAction method that I'll associate with a close button in
// the UI. We'll call the delegate's childViewController:didChooseValue: 
// method inside this handler.
- (IBAction)handleCloseButton:(id)sender;

@end

// 3. Definition of the delegate's interface
@protocol ChildViewControllerDelegate <NSObject>

- (void)childViewController:(ChildViewController*)viewController 
             didChooseValue:(CGFloat)value;

@end
希望这有帮助


首先非常感谢,我没有使用任何代码,但我使用了函数:-(Void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(nsindepath*)indexpath我更新了我的问题,也许你可以帮我解决这个问题
ViewController.m
#import "ChildViewController.h"

@implementation ChildViewController

- (void)handleCloseButton:(id)sender {
    // Xcode will complain if we access a weak property more than 
    // once here, since it could in theory be nilled between accesses
    // leading to unpredictable results. So we'll start by taking
    // a local, strong reference to the delegate.
    id<ChildViewControllerDelegate> strongDelegate = self.delegate;

    // Our delegate method is optional, so we should 
    // check that the delegate implements it
    if ([strongDelegate respondsToSelector:@selector(childViewController:didChooseValue:)]) {
        [strongDelegate childViewController:self didChooseValue:self.slider.value];
    }
}

@end
RootViewController.h

#import <UIKit/UIKit.h>
#import "ChildViewController.h"

@interface RootViewController : UITableViewController <ChildViewControllerDelegate>

@end
RootViewController.m

#import "RootViewController.h"

@implementation RootViewController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    ChildViewController *detailViewController = [[ChildViewController alloc] init];
    // Assign self as the delegate for the child view controller
    detailViewController.delegate = self;
    [self.navigationController pushViewController:detailViewController animated:YES];
}

// Implement the delegate methods for ChildViewControllerDelegate
- (void)childViewController:(ChildViewController *)viewController didChooseValue:(CGFloat)value {

    // Do something with value...

    // ...then dismiss the child view controller
    [self.navigationController popViewControllerAnimated:YES];
}

@end