Enclosed is some code that is supposed to input data to a table view, then load it onto a custom view. I created two classes, TVcontoller and CVcontroller. TVcontroller is an NSObject, CVcontroller a custom view class. There is a textfield, two buttons, a tableview, and a customview. When you type into the textfield and hit enter, it loads it onto the table view. This is done in TVcontroller. The intention was when you press the second button, in CVcontroller, it should load the selecteditem in the table view onto the customview as a string.
The problem I am having is that the nsmutablearray is not seen in CVcontroller, even though I imported TVcontroller.h and .m. I tried to put the whole project into a zip file but it was 2.3 mb. Below are the two .m files. Thanks for any help.
Adam
// TVcontroller.m
// asmcv3
//
// Created by Adam Martin on 4/25/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "TVcontroller.h"
@implementation TVcontroller
-(id)init
{
[super init];
myArray=[[NSMutableArray alloc]init];
[tableView setDelegate:self];
return self;
}
-(IBAction)button1
id)sender
{
myString=[myTextField stringValue];
[myTextField setStringValue
""];
[myArray addObject:myString];
[tableView reloadData];
}
-(int)numberOfRowsInTableView
NSTableView *)tv
{
return [myArray count];
}
-(id)tableView
NSTableView *)tv objectValueForTableColumn
NSTableColumn *)tableColumn row
int)row
{
return [myArray objectAtIndex:row];
}
@end
// CVcontroller.m
// asmcv3
//
// Created by Adam Martin on 4/25/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "CVcontroller.h"
#import "TVcontroller.m"
#import "TVcontroller.h"
@implementation CVcontroller
- (id)initWithFrame
NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect
NSRect)rect {
myPath=[NSBezierPath bezierPathWithRect:rect];
NSColor*myColor=[NSColor blueColor];
[myColor set];
[myPath fill];
myPointA=NSMakePoint((rect.size.width/2-25),(rect.size.height/2-25));
myPointB=NSMakePoint((rect.size.width/2-25)+50,(rect.size.height/2-25));
myPointC=NSMakePoint((rect.size.width/2-25)+50,(rect.size.height/2-25)+50);
myTriangle=[NSBezierPath bezierPath];
[myTriangle moveToPoint:myPointA];
[myTriangle lineToPoint:myPointB];
[myTriangle lineToPoint:myPointC];
[myTriangle closePath];
[[NSColor yellowColor]set];
[myTriangle fill];
}
-(IBAction)button2
id)sender
{
myString3=[myArray objectAtIndex:[tableView selectedRow]];
myPointD=NSMakePoint(0,0);
[myString3 drawAtPoint:myPointD withAttributes:nil];
}
@end
The problem I am having is that the nsmutablearray is not seen in CVcontroller, even though I imported TVcontroller.h and .m. I tried to put the whole project into a zip file but it was 2.3 mb. Below are the two .m files. Thanks for any help.
Adam
// TVcontroller.m
// asmcv3
//
// Created by Adam Martin on 4/25/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "TVcontroller.h"
@implementation TVcontroller
-(id)init
{
[super init];
myArray=[[NSMutableArray alloc]init];
[tableView setDelegate:self];
return self;
}
-(IBAction)button1
{
myString=[myTextField stringValue];
[myTextField setStringValue
[myArray addObject:myString];
[tableView reloadData];
}
-(int)numberOfRowsInTableView
{
return [myArray count];
}
-(id)tableView
{
return [myArray objectAtIndex:row];
}
@end
// CVcontroller.m
// asmcv3
//
// Created by Adam Martin on 4/25/09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "CVcontroller.h"
#import "TVcontroller.m"
#import "TVcontroller.h"
@implementation CVcontroller
- (id)initWithFrame
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}
- (void)drawRect
myPath=[NSBezierPath bezierPathWithRect:rect];
NSColor*myColor=[NSColor blueColor];
[myColor set];
[myPath fill];
myPointA=NSMakePoint((rect.size.width/2-25),(rect.size.height/2-25));
myPointB=NSMakePoint((rect.size.width/2-25)+50,(rect.size.height/2-25));
myPointC=NSMakePoint((rect.size.width/2-25)+50,(rect.size.height/2-25)+50);
myTriangle=[NSBezierPath bezierPath];
[myTriangle moveToPoint:myPointA];
[myTriangle lineToPoint:myPointB];
[myTriangle lineToPoint:myPointC];
[myTriangle closePath];
[[NSColor yellowColor]set];
[myTriangle fill];
}
-(IBAction)button2
{
myString3=[myArray objectAtIndex:[tableView selectedRow]];
myPointD=NSMakePoint(0,0);
[myString3 drawAtPoint:myPointD withAttributes:nil];
}
@end