Objective c 正在传回数据:未调用委托方法

Objective c 正在传回数据:未调用委托方法,objective-c,delegates,oauth-2.0,tableview,gdata,Objective C,Delegates,Oauth 2.0,Tableview,Gdata,我正在使用oauth 2.0开发一个与google文档连接的应用程序,一旦用户连接,他就会单击一个按钮,进入tableView以显示所有文档。为此,我使用segue并向前传递数据。现在,我希望用户选择一个文档,在其上打一个复选标记,然后返回到viewcontroller,将数据传递回并显示选中的文档。我读到,为了传回数据,我需要使用协议和委托。我遵循了这一点:但我的问题是没有调用我的委托方法 这是我的故事板,只有两个视图,一个视图控制器和一个名为vistatableviewvcontroller

我正在使用oauth 2.0开发一个与google文档连接的应用程序,一旦用户连接,他就会单击一个按钮,进入tableView以显示所有文档。为此,我使用segue并向前传递数据。现在,我希望用户选择一个文档,在其上打一个复选标记,然后返回到viewcontroller,将数据传递回并显示选中的文档。我读到,为了传回数据,我需要使用协议和委托。我遵循了这一点:但我的问题是没有调用我的委托方法

这是我的故事板,只有两个视图,一个视图控制器和一个名为
vistatableviewvcontroller
的tablaviewvcontroller

当用户按下authenticate按钮时,他使用oauth连接google文档。当他按下“列表”按钮时,VistaTableViewController出现

以下是VistaTableViewController.h的代码,其中a定义了协议:

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


@class VistaTableViewController;

@protocol VistaTableViewControllerDelegate <NSObject>
- (void)loqueselecciono:(VistaTableViewController *)controller didSelectDoc:(NSString *)documento;
@end


@interface VistaTableViewController : UITableViewController <UITableViewDataSource>
{
    IBOutlet UITableView *tablalistar;
    GDataFeedDocList *mDocListFeed2;
}

@property (nonatomic, weak) id <VistaTableViewControllerDelegate> delegate;
@property (nonatomic, strong) NSString *documento;
@property (nonatomic, retain) GDataFeedDocList *mDocListFeed2;

@end
好的,现在我只需要告诉ViewController导入VistaTableViewController并遵守其协议

这是ViewController.h的代码

#import <UIKit/UIKit.h>
#import "GTMOAuth2ViewControllerTouch.h"
#import "GData.h"
#import "VistaTableViewController.h"

@interface ViewController : UIViewController <VistaTableViewControllerDelegate>

- (GDataServiceGoogleDocs *)docsService;
- (void)authorize;
- (void) mifetch;
- (IBAction)autenticarse;
- (IBAction)listar:(id)sender;
- (void) ticket: (GDataServiceTicket *) ticket finishedWithFeed: (GDataFeedDocList *) feed error: (NSError *) error;

@property (nonatomic, retain) NSString *accessToken;
@property (nonatomic, retain) GDataFeedDocList *mDocListFeed;
@property (nonatomic, retain) GDataServiceTicket *mDoclistFetchTicket;


@end
在Viewcontroller.m中,我写这个是为了将self分配给代理

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Make sure your segue name in storyboard is the same as this line
    if ([[segue identifier] isEqualToString:@"displaydocs"])
    {
        VistaTableViewController *vistatableview = [[VistaTableViewController alloc] init];

        vistatableview.delegate = self;

        vistatableview = [segue.destinationViewController performSelector:@selector(setMDocListFeed2:) withObject:mDocListFeed];
    }
}
好的,我得到了显示所有文档的de tableView,用户可以选择一个显示de checkmark的,但是委托方法没有被调用,因此它不会返回到viewcontroller视图,也不会传回任何数据


我错过了什么??谢谢

当您编写
VistaTableViewController*vistatableview=[[VistaTableViewController alloc]init]时您正在创建一个新对象。您真正想要做的是使用
segue.destinationViewController
,它应该是
VistaTableViewController
,并将它的委托设置为
自我

按原样,具有委托的对象不是正在推送和处理视图逻辑的对象

(另外,
setMDocListFeed2
不返回对象,因此
performSelector
上的赋值相当误导。)

- (void)loqueselecciono:(VistaTableViewController *)controller didSelectDoc:(NSString *)documento;
{
    [self.navigationController popViewControllerAnimated:YES];

    UIAlertView *alertView = [ [UIAlertView alloc] initWithTitle:@"doc seleccionado"
                                                         message:[NSString stringWithFormat:@"titulo: %@", documento]
                                                        delegate:self
                                               cancelButtonTitle:@"Dismiss"
                                               otherButtonTitles:nil];

    [alertView show];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Make sure your segue name in storyboard is the same as this line
    if ([[segue identifier] isEqualToString:@"displaydocs"])
    {
        VistaTableViewController *vistatableview = [[VistaTableViewController alloc] init];

        vistatableview.delegate = self;

        vistatableview = [segue.destinationViewController performSelector:@selector(setMDocListFeed2:) withObject:mDocListFeed];
    }
}