English 中文(简体)
不可克减的意见没有显示我的数据。 为什么发生这种情况?
原标题:NSTableView is not showing my data. Why is that happening?

I m 制作“模拟”至单列项目,在公路上投入少数ump。 问题在于,我的NSTableView是NOT,显示了NSMutableArray“myArray”的数据,我不知道为什么。 谁能指出我的错误?

/*
 IBOutlet NSTextField *textField;
 IBOutlet NSTabView *tableView;
 IBOutlet NSButton *button;
 NSMutableArray *myArray;
 */

#import "AppController.h"


@implementation AppController


-(IBAction)addNewItem:(id)sender
{

    NSString *myString = [textField stringValue];

    NSLog(@"my stirng is %@",myString);
    myArray = [[NSMutableArray alloc] initWithCapacity:100];
    [myArray addObject:myString];

}

- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
    return [myArray count];
}
- (id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
            row:(int)rowIndex
{

    return [myArray objectAtIndex:rowIndex];
}

-(id)init
{
    [super init];
    [tableView setDataSource:self];
    [tableView setDelegate:self];

    NSLog(@"init");
    return self;
}

@end
最佳回答

问题是,在您的<代码>-init方法中,表格 观点变量仍将是零。 当装上刀具时,它首先制造并初步确定在刀子中申报的所有物体,然后才在两岸之间建立联系(传单、约束器、行动)。 取决于所建立的各种行动、渠道或约束的您的初始化法,需要列入<代码>-(避免)awakeFrom Nib。 方法不是<代码>-init方法。 您还可以把桌子的数据来源和投放点放在外围建筑商,从主机窗户的表格中抽取,然后选择每个小块。

而且,如果你改变其基本数据,你需要打上<条码>[表View reloadData],以便填写表格。 反映这些变化的观点。 在你看来,你需要用你——新的系统——方法——来说。 因此,你的法典应当研究这样的内容:

@implementation AppController
- (id)init
{
    if (nil == (self = [super init])) return nil;
    myArray = [[NSMutableArray alloc] init];
    return self;
}
- (void)dealloc
{
    [myArray release];
    [super dealloc];
}
- (void)awakeFromNib
{
    // assuming you re not just setting up these outlets in IB
    [tableView setDataSource:self];
    [tableView setDelegate:self];
}
-(IBAction)addNewItem:(id)sender
{
    [myArray addObject:[textField stringValue]];
    [tableView reloadData];
}
// data source methods same as in your code
@end
问题回答

暂无回答




相关问题
Asynchronous request to the server from background thread

I ve got the problem when I tried to do asynchronous requests to server from background thread. I ve never got results of those requests. Simple example which shows the problem: @protocol ...

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 ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

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 ...

iPhone numberpad with decimal point

I am writing an iPhone application which requires the user to enter several values that may contain a decimal point (currency values, percentages etc.). The number of decimal places in the values ...

热门标签