• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Simple TableView App (problem)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple TableView App (problem)


  • Subject: Re: Simple TableView App (problem)
  • From: email@hidden
  • Date: Sun, 3 Feb 2002 14:58:22 -0800

On Sunday, February 3, 2002, at 10:07 AM, Thilo Ettelt wrote:

Hi folks!

I'm experimenting with the TableView. The concept of a view and an object is pretty complicated for me, but I want to get it work. So I wrote a little app with a tableview, a textfield and a button, I connected everything properly in the IB. The PB shows up no errors when compiling, but the function, that should be provided by the app doesn't work. It should simply add a row to the tableview...

Can anybody help me?

create an instance of this class (Datasource) in IB.
create a table, connect it to the table outlet
create two textfields (or an NSForm with two NSFormCell's) and connect them to the name and address outlets.
create a button, connect it's action to the addValue: action

#import <Cocoa/Cocoa.h>

@interface Datasource : NSObject
{
NSMutableArray *table_data;
IBOutlet id address;
IBOutlet id name;
IBOutlet id table;
}
- (IBAction)addValue:(id)sender;
@end

#import "Datasource.h"

@implementation Datasource

- (void)dealloc
{
[table_data release];
[super dealloc];
}

- (id)init
{
if (self = [super init]) {
table_data = [[NSMutableArray alloc] init];
}
return self;
}

- (IBAction)addValue:(id)sender
{
NSString *nameval = [name stringValue];
NSString *addrval = [address stringValue];
if ([nameval length] > 0 && [addrval length] > 0) {
[table_data addObject:[NSDictionary dictionaryWithObjectsAndKeys:
nameval, @"name",
addrval, @"address",
nil]];
[table reloadData];
[name setStringValue:@""];
[address setStringValue:@""];
}
}

- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
{
return [[table_data objectAtIndex:rowIndex] objectForKey:[aTableColumn identifier]];
}

- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [table_data count];
}

@end


References: 
 >Simple TableView App (problem) (From: Thilo Ettelt <email@hidden>)

  • Prev by Date: Re: Simple TableView App (problem)
  • Next by Date: Re: Simple TableView App (problem)
  • Previous by thread: Re: Simple TableView App (problem)
  • Next by thread: Re: Simple TableView App (problem)
  • Index(es):
    • Date
    • Thread