首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未填充NSTableView

未填充NSTableView
EN

Stack Overflow用户
提问于 2012-05-25 03:10:15
回答 2查看 351关注 0票数 0

在过去的7个小时里,我一直在尝试让这个NSTableView填充。我正在尝试获取当前正在运行的所有应用程序的列表,并将它们放入NSTableView中。最后,我想解析结果,并将PID组织在一列中,将应用程序包组织在另一列中。我在“return listOfWindows objectAtIndex:row;”上收到一个EXC_BAD_ACCESS错误,我目前使用的是Xcode4.3.2,运行的是OS X Lion 10.7.4。提前感谢大家!

代码语言:javascript
复制
@interface AppDelegate : NSObject <NSApplicationDelegate>
{
    IBOutlet NSMenu *statusMenu;
    IBOutlet NSButton *button;
    IBOutlet NSWindow *menuWindow;
    IBOutlet NSTableView *proTable;
    NSArray *listOfWindows;
    IBOutlet NSArrayController *arrayController;
    AppDelegate *mainMenu;
    NSWorkspace  *workSpace;

    NSStatusItem *statusItem;
}

@property (assign) IBOutlet NSWindow *window;

-(IBAction)loadConfig:(id)sender;
@end

#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window = _window;


- (void) awakeFromNib
{   
[[NSDistributedNotificationCenter defaultCenter] addObserver:self
                                                                         selector:@selector(loadMenu:) 
                                                              name:@"WhiteBox"
                                                      object:nil];
[self addStatusItem];

 //[proTable setDataSource:self];

listOfWindows = [[NSWorkspace sharedWorkspace] runningApplications];
NSLog(@"index %@", listOfWindows);

int y = 0;
y = [listOfWindows count];
NSLog(@"y = %d", y);

[proTable setAllowsMultipleSelection:YES];   
    }

-(void)applicationWillTerminate
{
    NSLog(@"Will Terminate");
}


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{

}


-(void)applicationDidResignActive:(NSNotification *)notification
{
    NSLog(@"Resign Active");

}

-(void) addStatusItem
{
    //Create a variable length status item from the system statusBar
    statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength];
    [statusItem retain];

//Set a Title for it
[statusItem setTitle:@"Status Item"];

    //Set an Image and an alternate image
    //[statusItem setImage:[NSImage imageNamed:@"lnc"]];
    //[statusItem setAlternateImage: [NSImage imageNamed:@"status"]];

    //Add a Tool Tip
    [statusItem setToolTip:@"Status Item Tooltip"];

    //Choose to highlight the item when clicked
    [statusItem setHighlightMode:YES];

    //To Trigger a method on click use the following two lines of code
[statusItem setMenu:statusMenu];
    //[statusItem setAction:@selector(loadMenu:)];

}

-(IBAction)loadConfig:(id)sender
{

    if(! [menuWindow isVisible] )
    {
        [menuWindow makeKeyAndOrderFront:sender];
    } else {
        [menuWindow performClose:sender];
    }

}


- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
    return [listOfWindows count];
}
- (id)tableView:(NSTableView *)tableView 
objectValueForTableColumn:(NSTableColumn *)tableColumn 
            row:(NSInteger)row
{
    return [listOfWindows objectAtIndex:row];
}



@end
EN

回答 2

Stack Overflow用户

发布于 2012-05-25 04:48:56

表视图的数据源是什么对象?在您发布的实现NSTableViewDataSource protocol的源代码中,我没有看到任何对象。

此外,您是否尝试过在各种数据源方法中放置断点,以查看调试器是否停止在这些断点中?如果没有,这通常是一个好兆头,您的数据源没有连接到您的表视图。

票数 0
EN

Stack Overflow用户

发布于 2012-05-25 08:34:34

当我运行你的代码时,我得到了:-NSRunningApplication copyWithZone::无法识别的选择器错误。这可以通过将tableView:objectValueForTableColumn:row:中的返回行更改为

返回[listOfWindows对象属性索引:行本地化名称];

NSRunningApplication不符合NSCopying,所以我不知道您是否可以将该类的实例放在表视图中。但是,您可以获得它的属性,如localizedName、processIdentifier和bundleIdentifier。

我以前在没有实现NSCopying的类中遇到过这个问题,我很高兴知道是否有人知道在表视图或大纲视图中使用这些类的方法。

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

https://stackoverflow.com/questions/10743826

复制
相关文章

相似问题

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