首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在控制器运行完成后,如何从appdelegate运行方法?

在控制器运行完成后,如何从appdelegate运行方法?
EN

Stack Overflow用户
提问于 2012-11-11 10:01:02
回答 1查看 437关注 0票数 0

这个想法是,我有一个自定义视图,用户可以在其中拖放一个或多个文件,控制器能够将文件的路径保存到一个数组中。

在用户将文件放入界面后,如何从AppDelegate运行方法?

我有这些文件:

AppDelegate.h:

代码语言:javascript
复制
#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSScrollView *table;
@property (assign) IBOutlet NSWindow *window;
@end

AppDelegate.m:

代码语言:javascript
复制
#import "AppDelegate.h"

    @implementation AppDelegate
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
        // Insert code here to initialize your application
    }

    @end

DropView.h:

代码语言:javascript
复制
#import <Cocoa/Cocoa.h>

@interface DropView : NSView <NSDraggingDestination>
@property (assign) IBOutlet NSScrollView *table;
@property NSArray *draggedFilePaths;
@end

DropView.m:

代码语言:javascript
复制
#import "DropView.h"

@implementation DropView
@synthesize draggedFilePaths;

- (id)initWithFrame:(NSRect)frame
{

    self = [super initWithFrame:frame];
    if (self) {
        [self registerForDraggedTypes:[NSArray arrayWithObject:NSURLPboardType]];
    }

    return self;
}

-(NSDragOperation)draggingEntered:(id<NSDraggingInfo>)sender{
    return NSDragOperationGeneric;
}

-(NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender{
    return NSDragOperationCopy;
}
-(BOOL)prepareForDragOperation:(id<NSDraggingInfo>)sender{
    return YES;
}

-(BOOL)performDragOperation:(id<NSDraggingInfo>)sender{
    NSPasteboard* prb;
    prb= [sender draggingPasteboard];
    draggedFilePaths = [prb propertyListForType:NSFilenamesPboardType];
    return YES;
}

- (void)concludeDragOperation:(id<NSDraggingInfo>)sender{
    [self setNeedsDisplay:YES];
    NSLog(@"path %@",draggedFilePaths);
    [self populateTable];
}

- (void)drawRect:(NSRect)dirtyRect
{
}

-(void)populateTable{
    NSLog(@"yes");
}

@end
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-11 13:41:21

将AppDelegate.h导入到DropView.m中,并从performDragOperation:方法调用要运行的方法。

代码语言:javascript
复制
-(BOOL)performDragOperation:(id<NSDraggingInfo>)sender{
    NSPasteboard* prb;
    prb= [sender draggingPasteboard];
    draggedFilePaths = [prb propertyListForType:NSFilenamesPboardType];
    [(AppDelegate *)[[NSApplication sharedApplication]delegate] doWhatever:draggedFilePaths]; 
    return YES;
}

其中doWhatever:是在应用程序委托中实现的方法。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13327952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档