2012-07-05 3 views
0

2 개의 열 x 및 y가있는 행을 추가하여 NSTable보기 앱을 만들려고합니다. x 열을 상수로 지정하고 y 열을 원한다면 단추를 누를 때마다 초기 숫자를 1 씩 증가 시키길 원합니다. 파일 .HNSTableView가 늘어나는 숫자를 추가합니다.

@implementation Number 

@synthesize x; 
@synthesize y; 


-(id) init { 
self=[super init]; 
if (self) { 
    int j; 
    x = 5; 
    y=2+j; 
    j++; 
} 

return self; 
} 

@end 

번호 :

#import <Foundation/Foundation.h> 
int j; 
@interface Number : NSObject { 
@private 
int x,y; 
} 

@property int x,y,j; 

@end 

그러나 Y 열의 수를하지 않습니다 여기

내 TableController 구현 코드

@implementation TableViewController 

-(id)init { 

self = [super init]; 
if (self) { 
    list = [[NSMutableArray alloc]init]; 

} 

return self; 
} 
-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { 
return [list count]; 
} 

-(id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { 
Number *p = [list objectAtIndex:row]; 
NSString *identifier = [tableColumn identifier]; 
return [p valueForKey:identifier]; 
} 

-(IBAction)add:(id)sender{ 

    [list addObject:[[Number alloc] init]]; 

    [tableView reloadData]; 

} 

-(void) dealloc { 
[super dealloc]; 
} 
@end 

및 번호 구현 파일입니다 추가 버튼을 누르면 1 씩 증가합니다. 추가 버튼을 누를 때마다 다시 설정되는 것 같습니다. 어떤 도움을 내가 뭘 잘못하고 있니? 많은 감사합니다.

답변

0

.h 파일에 j를 선언하십시오.

.f file: 
    int j; 

INT의하는 .m 파일 :이 작동하는 것 같다

-(id) init { 
self=[super init]; 
if (self) { 
    x = 5; 
    y=2+j; 
    j++; 
} 

return self; 
} 
+0

감사합니다. – ste4lth

관련 문제