2016-09-21 4 views
0

나는 Objective-C에 상당히 익숙하다. 그리고 iOS와 UITableView에 대한 많은 튜토리얼이 있지만 NSTableView를 통한 OS X 애플리케이션에는 거의 없다. 내 데이터를 검색 할 수있는 방법을 만들었지 만 마지막 줄에 오류가 발생합니다.NSTableView에 데이터를 다시로드하는 방법은 무엇입니까?

"개체 형식 ProductsViewController에서 속성 tableView를 찾을 수 없습니다".

내 테이블에 데이터를 다시로드하는 올바른 방법이나이 특정 인스턴스에 NSTableView를 사용해야하는 경우조차 모르겠습니까? NSTableView를 사용하는 것보다 데이터를 표시하는 더 좋은 방법이 있습니까?

#import "ProductsViewController.h" 
#import "Product.h" 

#define getDataURL @"http://myurl" 


@interface ProductsViewController() 

@end 

@implementation ProductsViewController 

@synthesize jsonArray, productsArray; 

- (void)viewDidLoad { 
[super viewDidLoad]; 



[self retrieveData]; 



} 

-(NSInteger)numberOfRowsInTable:(NSTableView *)tableView{ 

return productsArray.count; 
} 

- (void) retrieveData{ 

NSURL * url = [NSURL URLWithString:getDataURL]; 
NSData * data = [NSData dataWithContentsOfURL:url]; 

jsonArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil]; 

productsArray = [[NSMutableArray alloc] init]; 


for(int i = 0; i < jsonArray.count; i++){ 

    NSString * pID   = [[jsonArray objectAtIndex:i] objectForKey:@"id"]; 
    NSString * pName  = [[jsonArray objectAtIndex:i] objectForKey:@"product_name"]; 
    NSString * pPrice  = [[jsonArray objectAtIndex:i] objectForKey:@"product_price"]; 
    NSString * pDescription = [[jsonArray objectAtIndex:i] objectForKey:@"product_description"]; 
    NSString * pImage  = [[jsonArray objectAtIndex:i] objectForKey:@"product_image"]; 
    NSString * pDownload = [[jsonArray objectAtIndex:i] objectForKey:@"product_download"]; 
    NSString * pVideo  = [[jsonArray objectAtIndex:i] objectForKey:@"product_video"]; 
    NSString * pFeatured = [[jsonArray objectAtIndex:i] objectForKey:@"featured"]; 


    [productsArray addObject:[[Product alloc] initWithProduct_Name: pName andProduct_Price:pPrice andProduct_Description:pDescription andProduct_Image:pImage andProduct_Download:pDownload andProduct_Video:pVideo andProduct_Featured:pFeatured andProduct_ID:pID]]; 
} 

[self.tableView reloadData]; 


} 
+0

물론 'NSTableView'와 몇 가지 데이터 소스/위임 메소드 또는 코코아 바인딩이 필요합니다. – vadian

답변

1

NSTableViewDataSource 프로토콜에 필요한 위임 방법을 구현해야합니다. 특히 다음 두 가지가 필요합니다.

numberOfRowsInTableView: 
tableView:objectValueForTableColumn:row: 

테이블 뷰는 원하는 데이터에 대해 이러한 메서드를 호출합니다.

또한, raywenderlich.com에 NSTableViews 사용에 관한 a great tutorial이 있습니다.

+0

그게 전부입니다. 정말 고맙습니다! –

관련 문제