在过去的 7 个小时里,我一直试图让这个 NSTableView 填充。我正在尝试获取所有当前正在运行的应用程序的列表并将它们放入 NSTableView。最终,我想解析结果并将 PID 组织在一列中,将应用程序包组织在另一列中。我在“ return [listOfWindows objectAtIndex:row];”上收到 EXC_BAD_ACCESS 错误 我目前正在使用 Xcode 4.3.2 并运行 OS X Lion 10.7.4。提前谢谢大家!
@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