Re: Dynamically added text views
Re: Dynamically added text views
- Subject: Re: Dynamically added text views
- From: April Gendill <email@hidden>
- Date: Fri, 29 Aug 2003 09:38:18 -0700
There are just days.....
ok. I figured it all out. I'll have to play with adding the tabs a bit
but! as it stands what I have works quite nicely. so..... Just incase
any one is as dense as me and needs this advice I'll post all of the
code I have, it's dirty, but it works and could be cleaned and
streamlined. this is the part of the program that handles the tabs.
After I remembered to set the delegate in IB it all worked like a dream:
-(void)addUserTabs:(int)dKey{
NSString *destination = [[[NSHomeDirectory()
stringByAppendingPathComponent:@"Library"]
stringByAppendingPathComponent:@"Preferences"]
stringByAppendingPathComponent:@"data.txt"];
NSMutableDictionary *defaults=[NSMutableDictionary
dictionaryWithContentsOfFile:destination];
if (dKey =1){
NSString * firstTab;
firstTab=[defaults objectForKey:@"0"];
if([firstTab length]==0){
NSLog(@"Length is 0");
firstTab =@"";
}
[noteViewOne setString:firstTab];
}
aTabItem = [[NSTabViewItem alloc]init];
NSRect scrollRect = NSMakeRect(0.0,16.0,359.0,532.0);
NSScrollView *theScrollView = [[NSScrollView alloc]
initWithFrame:scrollRect];
[theScrollView setHasVerticalScroller:YES];
[theScrollView setHasHorizontalScroller:NO];
[aTabItem setView:theScrollView];
[theScrollView setFrame:scrollRect];
NSTextView *theTextView = [[NSTextView alloc]
initWithFrame:[theScrollView frame]];
[theScrollView setDocumentView:theTextView];
NSString *pageName=[NSString stringWithFormat:@"Page %i",dKey+1];
NSString *pageIdent2=[NSString stringWithFormat:@"%i",dKey+1];
[aTabItem setIdentifier:pageIdent2];
[aTabItem setLabel:pageName];
[theTabs addTabViewItem:aTabItem];
NSString * currentString=[defaults objectForKey:[NSString
stringWithFormat:@"%i",dKey]];
[theTextView setString:currentString];
//this method could be called in a loop to add as many tabs as needed
}
- (void)tabView:(NSTabView *)tabView
didSelectTabViewItem:(NSTabViewItem *)tabViewItem
{
int pgn=[theTabs indexOfTabViewItem:[theTabs selectedTabViewItem]];
pageNumber =pgn+1;
if(pageNumber >1){
NSScrollView *theScroll =[[theTabs selectedTabViewItem]view];
NSTextView *theText=[theScroll documentView];
}else{
NSString* theText= [firstTab string];
//this is all to do one thing, get the text so it can be saved or added
to a dictionary
//which i did not include here.
}
[pageNum setStringValue:[NSString
stringWithFormat:@"-%i-",pageNumber]];
}
-(IBAction)selectTabItem:(id)sender{
//Build the textview
//---
if([sender tag]==1){
[theTabs performSelector:@selector(selectNextTabViewItem:)];
if(pageNumber <[[theTabs tabViewItems]count]){
pageNumber++;
[pageNum setStringValue:[NSString
stringWithFormat:@"-%i-",pageNumber]];
NSScrollView *theScroll =[[theTabs selectedTabViewItem]view];
NSTextView *theText=[theScroll documentView];
NSLog(@"%@",[theText string]);
}
}else{
[theTabs performSelector:@selector(selectPreviousTabViewItem:)];
if(pageNumber >1){
pageNumber --;
[pageNum setStringValue:[NSString
stringWithFormat:@"-%i-",pageNumber]];
if(pageNumber >1){
NSScrollView *theScroll =[[theTabs selectedTabViewItem]view];
NSTextView *theText=[theScroll documentView];
NSLog(@"%@",[theText string]);
}else{
NSString* theText= [noteViewOne string];
NSLog(@"%@",theText);
}
[pageNum setStringValue:[NSString
stringWithFormat:@"-%i-",pageNumber]];
}
}
}
On Friday, August 29, 2003, at 08:55 AM, Alastair J.Houghton wrote:
>
On Friday, August 29, 2003, at 04:32 pm, April Gendill wrote:
>
>
> I understand needing to pass a pointer and getting the value that
>
> would be pretty much exactly what's done with IB. what I do not know
>
> how to do it to make that pointer. How do I access the view item to
>
> make a pointer to it.
>
>
You already have a pointer to it... you got one when you created the
>
text view) with a line like this (copied from your previous e-mail):
>
>
NSTextView *theTextView = [[NSTextView alloc]
>
initWithFrame:[theScrollView frame]];
>
>
All you have to do is store it somewhere.
>
>
Kind regards,
>
>
Alastair.
>
_______________________________________________
>
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.
_______________________________________________
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.