NSTableView (View Based)의 초보적 구현
10443 단어 MacOSXObjective-CNSTableView
개요

GitHub
htps : // 기주 b. 코 m / 뽀 m dau / 타 b ゔ ぃ 에 w_
구현 절차





AppDelegate.h
에서 변수 선언. // AppDelegate.h
// TableView_ViewBased
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (readwrite,nonatomic) NSMutableArray* tableData;
@end
AppDelegate.m
에 init을 추가하고 테이블에 표시 할 데이터를 초기화합니다.- (id)init{
self = [super init];
if (self) {
//テーブル表示データを初期化
_tableData = [NSMutableArray array];
[_tableData addObject: @{
@"name" : @"ピカチュウ",
@"type" : @"でんき"
}];
[_tableData addObject: @{
@"name" : @"ゼニガメ",
@"type" : @"みず"
}];
[_tableData addObject: @{
@"name" : @"ヒトカゲ",
@"type" : @"みず"
}];
[_tableData addObject: @{
@"name" : @"フシギダネ",
@"type" : @"くさ"
}];
}
return self;
}

TableController.m
에 TableView 표시에 필요한 함수를 작성한다. AppDelegate
에서 데이터를 당기기 때문에 import를 잊지 마세요. #import "TableController.h"
#import "AppDelegate.h"
@implementation TableController
#pragma mark - NSTableView data source
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{
AppDelegate *appD = (AppDelegate*)[[NSApplication sharedApplication]delegate];
return appD.tableData.count;
}
// 使い方はセル・ベースのtableView:objectValueForTableColumn:row:とほとんど同じ。
// コラムをidentifierで特定してデータ・ソース配列の中のrowインデクスと同じインデクスの値を返してやる。
// ビュー・ベースの場合はその値を当てがったセル・ビューを返すというだけだ。
- (NSView *)tableView:(NSTableView *)tableView
viewForTableColumn:(NSTableColumn *)tableColumn
row:(NSInteger)row{
AppDelegate *appD = (AppDelegate*)[[NSApplication sharedApplication]delegate];
NSString *identifier = tableColumn.identifier;
NSDictionary *data = [appD.tableData objectAtIndex:row];
NSTableCellView *cellView = [tableView makeViewWithIdentifier:identifier owner:self];
cellView.textField.stringValue = [data objectForKey:identifier];
return cellView;
}
@end
참고 사이트
이제 모든 클래스에서 볼 수 있습니다. 쉽습니다. 또한 앱이 실행되는 동안 AppDelegate 인스턴스는 언제든지 해제되지 않고 유지된다는 보장이 있다는 점도 있습니다.
Reference
이 문제에 관하여(NSTableView (View Based)의 초보적 구현), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/IKEH/items/743107c18ac6bd7228ad텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)