Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 为什么我的表视图不显示我的数据?_Objective C_Cocoa - Fatal编程技术网

Objective c 为什么我的表视图不显示我的数据?

Objective c 为什么我的表视图不显示我的数据?,objective-c,cocoa,Objective C,Cocoa,我有一个基于文档的应用程序,它有两个类:myDocument和Person。该界面包括一个用于显示数据的表视图和两个用于在表中添加和删除peson的按钮。myDocument类是数据源和委托。我实现了必要的委托方法,但当我单击按钮向表中添加记录时,表视图不会显示更改。有人能告诉我我做错了什么吗 #import "MyDocument.h" @implementation MyDocument - (id)init { self = [super init]; if (self

我有一个基于文档的应用程序,它有两个类:myDocument和Person。该界面包括一个用于显示数据的表视图和两个用于在表中添加和删除peson的按钮。myDocument类是数据源和委托。我实现了必要的委托方法,但当我单击按钮向表中添加记录时,表视图不会显示更改。有人能告诉我我做错了什么吗

#import "MyDocument.h"

@implementation MyDocument

- (id)init
{
    self = [super init];
    if (self) {

        // Add your subclass-specific initialization here.
        // If an error occurs here, send a [self release] message and return nil.
    _dataArray = [[NSMutableArray alloc]init];
    }
    return self;
}
-(IBAction)addPerson:(id)sender
{
 Person *newPerson = [[Person alloc] init];
 [_dataArray addObject:newPerson];

 NSLog(@" how many objects are in the table? %d",[_dataArray count]);
 //[newPerson release];
 [_tableView reloadData];
}
-(int)numberOfRowsInTableView:(NSTabView*)aTableView
{
 return [_dataArray count];
}


- (void)tableView:(NSTableView *)aTableView 
  willDisplayCell:(id)aCell 
   forTableColumn:(NSTableColumn *)aTableColumn 
     row:(NSInteger)rowIndex
{
 [_dataArray objectAtIndex:rowIndex];
 NSLog(@" this is the object? %@",[_dataArray objectAtIndex:rowIndex]);
 [_tableView reloadData];
}
- (id) tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
    row:(int)rowIndex
{
 //NSLog(@"this is the object %@",[array objectAtIndex:rowIndex]);
 NSLog(@"this is what is in the array %@",[_dataArray objectAtIndex:rowIndex]);
 return [_dataArray objectAtIndex:rowIndex];
 //return [array replaceObjectAtIndex:[tableView selectedRow ]  withObject: @"Micheal jordan"];
}

- (NSString *)windowNibName
{
    // Override returning the nib file name of the document
    // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
    return @"MyDocument";
}

- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
    [super windowControllerDidLoadNib:aController];
    // Add any code here that needs to be executed once the windowController has loaded the document's window.
}

- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError
{
    // Insert code here to write your document to data of the specified type. If the given outError != NULL, ensure that you set *outError when returning nil.

    // You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead.

    // For applications targeted for Panther or earlier systems, you should use the deprecated API -dataRepresentationOfType:. In this case you can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead.

    if ( outError != NULL ) {
  *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
 }
 return nil;
}

- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
{
    // Insert code here to read your document from the given data of the specified type.  If the given outError != NULL, ensure that you set *outError when returning NO.

    // You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead. 

    // For applications targeted for Panther or earlier systems, you should use the deprecated API -loadDataRepresentation:ofType. In this case you can also choose to override -readFromFile:ofType: or -loadFileWrapperRepresentation:ofType: instead.

    if ( outError != NULL ) {
  *outError = [NSError errorWithDomain:NSOSStatusErrorDomain code:unimpErr userInfo:NULL];
 }
    return YES;
}

@end

检查是否实际初始化了_tableviewoutlet以指向表视图。

我设置了outlet文件的所有者您需要将MyDocument或文件所有者的_tableviewoutlet链接到窗口内的实际表视图对象。