代表不起作用

时间:2013-09-08 09:27:59

标签: ios objective-c

您好在此代码中协议RefreshLibraryDropBoxDelegate不起作用,不会调用WVdALibraryDocumentViewController中的方法refreshLibrary。为什么呢?

WVdADropboxViewController.h

#import <UIKit/UIKit.h>
#import <DropboxSDK/DropboxSDK.h>

@protocol RefreshLibraryDropBoxDelegate <NSObject>
@optional

-(void)refreshLibrary;

@end

@interface WVdADropboxViewController : UIViewController <DBRestClientDelegate, UITableViewDataSource, UITableViewDelegate>
{
id <RefreshLibraryDropBoxDelegate> delegate;
}

//delegate
@property (assign) id <RefreshLibraryDropBoxDelegate> delegate;

WVdADropboxViewController.m:

- (void)restClient:(DBRestClient *)client loadedFile:(NSString *)destPath
{
NSLog(@"upload complete");
[self.delegate refreshLibrary];
[[self navigationController]  popViewControllerAnimated:YES];
}

WVdALibraryDocumentViewController.h:

#import <UIKit/UIKit.h>
#import "WVdACustomCell.h"
#import "WVdAViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "WVdADropboxViewController.h"


@interface WVdALibraryDocumentViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate, RefreshLibraryDropBoxDelegate>
-(void)refreshLibrary;

WVdALibraryDocumentViewController.m:

// REFRESH LIBRARY //
-(void)refreshLibrary
{
     NSLog(@"refresh");
     [self getDataArrayDocumentFiles];
}

2 个答案:

答案 0 :(得分:1)

您不需要此行

{
id <RefreshLibraryDropBoxDelegate> delegate;
}

然后,在WVdALibraryDocumentViewController

您需要在viewDidLoad或其他地方设置

WVdADropboxViewController *myCoolController = [WVdADropboxViewController new];
myCoolController.delegate = self;

它应该工作!

答案 1 :(得分:0)

我想你可以在WVdALibraryDocumentViewController.m中设置委托。

在WVdALibraryDocumentViewController中的viewDidLoad中:

wVdADropboxViewController.delegate = self;