English 中文(简体)
NSTV 不传播
原标题:NSTableView not Populating

我试图让这个NSTableView在过去7小时中进行填充。 我正试图获取一个当前所有应用程序的清单, 并将其放入NSTableView。 最后我想将结果解析, 并将 PID 组织成一列, 将应用程序捆绑在另一列中。 我正在获取一个 EXC_BAD_ACCESS 错误, 内容是“ 返回 [ listofWindows objectalAtIndex:row] ; ” 我正在使用 Xcode 4. 3. 3.2 并运行 OS X 狮子 10. 7. 。 感谢大家!

@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
问题回答

表格视图数据源是什么? 我看不到您张贴在源代码中用于执行 NSTableDataSource 协议

此外,您是否尝试在各种数据源方法中设置断点, 以查看调试器是否停在其中? 如果没有, 它通常是一个好的迹象, 即您的数据源与您的表格视图没有连接 。

我得到了: - [NSRunning Application Application ActForZone::]:: 当我运行您的代码时, 未知的选择器错误。 这可以通过修改表V: object ValueFor TableColumn: row: to: 修改您的返回线来修正 。

返回 [ [列出窗口对象AtIndex:row] 本地化Name];

NSRunning Application 不符合NSCopying, 所以我不知道您是否可以将该类的例子放在表格视图中。 但是, 您可以得到其属性, 如本地化名称、 进程识别符和捆绑识别符 。

我遇到过这个问题之前, 班级不执行NSCopying, 我很想知道是否有人知道如何在表格观点或概要观点中使用这些课程。





相关问题
Taking picture with QTCaptureView

Is it possible to simply take a picture and save it somewhere using a QTCaptureView and Apple s built-in iSight? I ve seen lots of tutorials on recording video but none on simply taking a picture. Any ...

Controlling OSX windows

I m trying to control windows of a foreign OSX applications from my application. I d like to 1. move the windows on the screen 2. resize the windows on the screen 3. change the currently active window ...

objective-c: Calling a void function from another controller

i have a void, like -(void) doSomething in a specific controller. i can call it in this controller via [self doSomething], but i don t know how to call this void from another .m file. I want to call ...

NSUndoManager and runModalForWindow:

I have a simple Core Data app which displays a list of entities in the main window. To create or add new entities, I use a second modal window with a separate managed object context so changes can be ...

NSMutableArray values becoming "invalid"

I m trying to show a database information in a tableview and then the detailed information in a view my problem is as follow: I created a NSMutableArray: NSMutableArray *myArray = [[NSMutableArray ...

How to get a flash url in a webpage using a webframe?

As we know , When we load frame from webpage of safari, we will invoke the delegate methods of webkit informal protocol(WebFrameLoadDelegate): webView:didStartProvisionalLoadForFrame: webView:...

热门标签