Adding data to a TableView
Adding data to a TableView
- Subject: Adding data to a TableView
- From: Jeremy Dronfield <email@hidden>
- Date: Fri, 21 Jun 2002 17:13:36 +0100
I've got a feeling I'm missing something eye-poppingly obvious. Can
anyone explain what's going wrong with the following code? I can't get
it to work (either signal 6, signal 10 or signal 11, or just no response
at all). I've included some of the 'commented out' alternative bits of
code I've tried.
#import "MyController.h"
@implementation MyController
- (id)init
{
[super init];
bookmarks = [[NSMutableArray alloc] init];
/*[(NSMutableArray *)bookmarks init];*/
[bookmarks retain];
totalSegments = 4;
return self;
}
- (void)dealloc
{
[super dealloc];
}
////////////********ACCESSORS********////////////
- (NSButton *)markButton {
return markButton;
}
- (NSTableView *)bmTableViewBody {
return bmTableViewBody;
}
- (NSTextView *)someTextTextView {
return someTextTextView;
}
- (NSString *)textToBookmark {
return textToBookmark;
}
- (int)segmentCount {
return segmentCount;
}
- (NSMutableArray *)bookmarks {
return bookmarks;
}
////////////********METHODS********////////////
////////////********bookmarking********////////////
// Getting text
- (void)textViewDidChangeSelection:(NSNotification *)aNotification
{
if ([someTextTextView selectedRange].length > 0) {
textToBookmark=[[someTextTextView string]
substringWithRange:[someTextTextView
selectedRange]];
[[self markButton] setEnabled:YES];
} else {
[[self markButton] setEnabled:NO];
}
}
// Marking
- (IBAction)markAction:(id)sender
{
[bookmarks addObject:[self createBookmark]];
[bmTableViewBody reloadData];
}
- (NSDictionary *)createBookmark
{
NSMutableDictionary *bookmark = [NSMutableDictionary dictionary];
[bookmark setObject:[NSNumber numberWithInt:[self segmentCount]]
forKey:@"scv"];
[bookmark setObject:textToBookmark forKey:@"Bookmarks"];
return bookmark;
}
// Managing table
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [bookmarks count];
}
-(id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn row:
(int)rowIndex
{
id theBookmark, theValue;
NSParameterAssert(rowIndex >= 0 && rowIndex < [bookmarks count]);
theBookmark = [bookmarks objectAtIndex:rowIndex];
theValue = [theBookmark objectForKey:[aTableColumn identifier]];
return theValue;
}
@end
I'm desperate. Please help.
- Jeremy.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.