0

過去 7 時間、この NSTableView に値を設定しようとしてきました。現在実行中のすべてのアプリケーションのリストを取得して、それらを NSTableView に入れようとしています。最終的には結果を解析し、PID を 1 つの列に、アプリケーション バンドルをもう 1 つの列に整理したいと考えています。「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
4

2 に答える 2

0

次のようになりました:-[NSRunningApplication copyWithZone:]:コードを実行したときに認識されないセレクターエラー。これは、tableView:objectValueForTableColumn:row:の戻り行をに変更することで修正できます。

return [[listOfWindows objectAtIndex:row] localedName];

NSRunningApplicationはNSCopyingに準拠していないため、そのクラスのインスタンスをテーブルビューに配置できるかどうかはわかりません。ただし、localizedName、processIdentifier、bundleIdentifierなどのプロパティを取得できます。

NSCopyingを実装していないクラスでこの問題に遭遇したことがあります。テーブルビューまたはアウトラインビューでこれらのクラスを使用する方法を誰かが知っているかどうかを知りたいと思います。

于 2012-05-25T00:34:34.090 に答える
0

テーブル ビューのデータ ソースはどのオブジェクトですか? あなたが投稿したソースには、NSTableViewDataSourceprotocolを実装するオブジェクトがありません。

さらに、デバッガーが停止するかどうかを確認するために、さまざまなデータ ソース メソッドにブレークポイントを配置しようとしましたか? そうでない場合は、通常、データ ソースがテーブル ビューに接続されていないことを示しています。

于 2012-05-24T20:48:56.007 に答える