NSTextView inside NSTabviewItem, loading text delay - macos

I am using NSSplitview of which upper half is NSTableView and lower is NSTabview with 2 items. Each NStabViewItem has a NSTextview. All are defined in nib file.
Now on selection of row of NSTableview, I load content of file and set it on NSTextview of NSTabViewItem. so NSTabview items I load depending on what rows of NSTableView is selected.
However I observe appreciable delay of 5-6 seconds to see the text visible on NSTextview of NSTabViewItem of NSTabView.But if I hover the mouse in the NSTabView region the content of NSTextview of NSTabViewItem of NSTabview is shown immediately.
Can anybody guide me what is the issue?
I am only using NSTableView delegate, Not tabview delegate. I just load the content in respective NSTextView of each NSTabViewItem of tabview.
Code Snippet:
- (void)tableViewSelectionDidChange:(NSNotification *)notification
{
if ([mTableView selectedRow] != -1)
{
selectedNode = [mLogContainer objectAtIndex:[mTableView selectedRow]];
[self manageTabView:[selectedNode logfile]];
}
}
-(void) manageTabView:(NSString*) fname
{
[self loadTextView:mDetailView withFilePath:fname];
NSString* summaryFile = [NSString stringWithFormat:#"%#.summary",fname];
[self loadTextView:mSummaryView withFilePath:summaryFile];
[mTabView selectTabViewItemAtIndex:0];
}
-(void) setContent:(NSString*) content forView:(NSTextView*) textView
{
NSString* fileContent = [[NSString alloc] init];
[fileContent stringWithContentsOfFile:content
encoding:NSUTF8StringEncoding error:nil];
NSTextStorage *textStorage = [textView textStorage];
[textStorage beginEditing];
[[textStorage mutableString] setString:fileContent];
[textStorage endEditing];
[textView setNeedsDisplay:YES];
}

How much ever stupid it may sound, but the problem of this weird behavior was that the NStextview in the nib frame was a bit bigger than the NSTabviewItem view. Not sure what is the reason for this behavior but when I re-sized the NSTextView .. Everything is working fine.

Related

NSTableView + NSProgressIndicator flickering issues

I have a NSTableView which contains two columns, a NSTextField and a NSProgressIndicator object on each row. When I scroll up or down the NSProgressIndicator objects flicker, the same occurs when I select the text contained in the NSTextField. Does anyone know why?
This is the code I am using for creating the NSProgressIndicator objects in the 'viewForTableColumn' method:
...
if ([identifier isEqualToString:#"Progress"]) {
NSProgressIndicator* progressIndicator = (NSProgressIndicator*)cellView.nextKeyView;
NSString *stringPercentage = [dictionary objectForKey:#"Percentage"];
[[progressIndicator animator] setDoubleValue:[stringPercentage doubleValue]];
}
...
Note: NSTextField's are only selectable (not editable).
I could fix this by using:
[progressIndicator setUsesThreadedAnimation:NO];
So that the final code is:
...
if ([identifier isEqualToString:#"Progress"]) {
NSProgressIndicator* progressIndicator = (NSProgressIndicator*)cellView.nextKeyView;
NSString *stringPercentage = [dictionary objectForKey:#"Percentage"];
[[progressIndicator animator] setDoubleValue:[stringPercentage doubleValue]];
[progressIndicator setUsesThreadedAnimation:NO];
}
...

Adding NSTableView to NSView Programmatically

I am having a bit of trouble adding a NSTableView to an NSView programatically. The view is the first view of an NSSplitView. My Pointers are set up right i am sure of it because I can add a NSButton to the view no problem. Also my tableview's delegate and datasource methods are working as expected. If I use interface builder to add the table view to my view it works. However, I dont want to use IB. I would like to be able to do this through code. Here is the code I am currently using.
-(void)awakeFromNib{
tableData = [[NSMutableArray alloc]initWithObjects:#"March",#"April",#"May", nil];
tableView = [[NSTableView alloc]initWithFrame:firstView.frame];
[tableView setDataSource:self];
[tableView setDelegate:self];
[firstView addSubview:tableView];
NSButton *j = [[NSButton alloc]initWithFrame:firstView.frame];
[j setTitle:#"help"];
[firstView addSubview:j];
}
The NSButton object appears on screen although if I comment out the button the tableview does not appear. What am I doing wrong. Thanks for the help.
Thank you, from your help I was able to figure this out. IB automatically inserts the NSScrollview around the table view and it also inserts a column for you. In order to do it this from code you need to allocate a scroll view and a column. Here is what I am currently utilizing if anyone else comes across this problem.
-(void)awakeFromNib{
tableData = [[NSMutableArray alloc]initWithObjects:#"March",#"April",#"May", nil];
NSScrollView * tableContainer = [[NSScrollView alloc] initWithFrame:firstView.bounds];
//This allows the view to be resized by the view holding it
[tableContainer setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
tableView = [[NSTableView alloc] initWithFrame:tableContainer.frame];
[tableView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
NSTableColumn *column =[[NSTableColumn alloc]initWithIdentifier:#"1"];
[column.headerCell setTitle:#"Header Title"];
[tableView addTableColumn:column];
[tableView setDataSource:self];
[tableView setDelegate:self];
[tableContainer setDocumentView:tableView];
[firstView addSubview:tableContainer];
//You mentioned that ARC is turned off so You need to release these:
[tableView release];
[tableContainer release];
[column release];
}
Thanks for your help.
NSTableView by default is in NSScrollView. So You can do it like this:
tableData = [[NSMutableArray alloc] initWithObjects:#"March",#"April",#"May", nil];
NSScrollView * tableContainer = [[NSScrollView alloc] initWithFrame:firstView.frame];
tableView = [[NSTableView alloc] initWithFrame:firstView.frame];
[tableView setDataSource:self];
[tableView setDelegate:self];
[tableContainer setDocumentView:tableView];
[firstView addSubview:tableContainer];
//You mentioned that ARC is turned off so You need to release these:
[tableView release];
[tableContainer release];

cocoa objective c pdfview not loaded

I am a newbie for MAC development, I have a simple Cocoa Application using NSViewController where I have a main view and 2 NSViewController and dynamically flipping them. I have added PDFView on NSViewController view to show pdf pages flipping at run time. but my problem when the views are added dynamically then on PDFView I can see the pdf page after resizing the window. I tried using [[pdfViewOutlet1 view] setNeedsDisplay:YES]; for both the views.
FirstView *FirstViewController = [[FirstView alloc] initWithNibName:kFirstView bundle:nil];
[FirstViewController setPdfDoc:pdfDoc];
[FirstViewController setPageCnt:pageCnt];
self.myCurrentViewController = FirstViewController;
[[_myCurrentViewController view] setNeedsDisplay:YES];
[transition setSubtype:kCATransitionFromLeft];
[[_myTargetView animator] addSubview: [_myCurrentViewController view]];
and in the awakeFromNib: method of first view I have:
if(pdfDoc==nil )
return;
[pdfViewOutlet1 setDisplayMode: kPDFDisplaySinglePageContinuous]; //kPDFDisplaySinglePage or kPDFDisplayTwoUp;
[pdfViewOutlet1 setDocument:pdfDoc];
NSRect myRect = { { 0,0 }, { 450, 200 } };
[pdfViewOutlet1 setFrame: myRect];
[pdfViewOutlet1 goToPage: [[pdfViewOutlet1 document] pageAtIndex: pageCnt]];
[pdfDoc release];
[[pdfViewOutlet1 view] setNeedsDisplay:YES];
How can I see the pdf pages without resizing the views using mouse?
the issue is solved, i was using setWantsLayer on my Parent view which was creating the issue.

How to make NSTableView transparent?

I want to make transparent NSTableView.
I am using WindowController class here.
I was trying this:
- (void)windowDidLoad
{
[super windowDidLoad];
[[self enclosingScrollView] setDrawsBackground: NO];
[[self enclosingScrollView] setBorderType:NSNoBorder];
}
- (BOOL)isOpaque {
return NO;
}
- (void)drawRect:(NSRect)drawRect
{
[super drawRect: drawRect];
}
But when i was writing this code i can't found enclosingScrollView in help window.
you can see here..
Any help?? Please remember me or correct me if i am doing something wrong.
Thank you.
If you have an NSScrollView enclosing your NSTableView, you can set the scroll view's drawsBackground property to NO like this:
yourScrollView.drawsBackground = NO;
Got Answer..!!! I just tried this
[tableview setBackgroundColor:[NSColor clearColor]];
[tableview setHeaderView:nil];
and its working fine.. – – Snehal
Copied from comment in question, as its a bit buried...
If your app needs to display a transparent table view, set the background color of the table view to be clear and set the enclosing scroll view to not draw its background. The following code snippet shows one way to display a transparent table:
Swift:
yourTableView.backgroundColor = NSColor.clear
yourTableView.enclosingScrollView?.drawsBackground = false
Objective-C
[theTableView setBackgroundColor:[NSColor clearColor];
[[theTableView enclosingScrollView] setDrawsBackground:NO];
Apple - Modifying a Table’s Visual Attributes

Custom NSScroller issues

I'm trying to subclass NSScroller in order to draw my own scroller knob. To do this, I've subclassex NSScrollView and usex the following code to instantiate my custom NSScrollers:
- (void)awakeFromNib;
{
NSRect horizontalScrollerFrame = [[self horizontalScroller] frame];
NSRect verticalScrollerFrame = [[self verticalScroller] frame];
NSString *scrollBarVariant = [[[NSUserDefaults standardUserDefaults] persistentDomainForName:NSGlobalDomain] valueForKey:#"AppleScrollBarVariant"];
if (![scrollBarVariant isEqualToString:#"DoubleBoth"]) {
[self setVerticalScroller:[[[TRScroller alloc] initWithFrame:verticalScrollerFrame] autorelease]];
[self setHorizontalScroller:[[[TRScroller alloc] initWithFrame:horizontalScrollerFrame] autorelease]];
}
}
This works and my NSScrollers display correctly. But I'm occasionally seeing rendering issues upon first loading my application. Within Interface Builder I have laid out a number of NSScrollViews with their scrollbars set to hide automatically. The issue I'm seeing is that when the application first loads, the scrollbar backgrounds are rendered across the NSScrollViews contents.
alt text http://www.freeimagehosting.net/uploads/1d3fc75db8.png
I believe this is because I instantiate my NSScroll subclass (TRSubclass) via awakeFromNib, which means that the scrollbars are given the frame of the NSScrollView before it is automatically resized to meet the windows saved location and size (in other words, it's using the frame that's assigned by default within Interface Builder). What's the best way around this?
I've tried forcing the NSScrollView to redisplay (using setNeedsDisplay: and display:) but with no luck. Has anyone else come across a similar issue?
I'm using the same schema in my applications and I fighted this issues a lot. I use the same trick: scrollers are substituted in [scrollView awakeFromNib] methods, but I don't face such rendering issues at the moment. You can try to play with "draws background" property of the NSScrollView - it really helps sometimes
- (void)changeSubs
{
// change clip view
// ...
// change scrollers
NSRect horizontalScrollerFrame = [[self horizontalScroller] frame];
NSRect verticalScrollerFrame = [[self verticalScroller] frame];
if (![[self verticalScroller] isKindOfClass:[CRScroller class]])
[self setVerticalScroller:[[[CRScroller alloc] initWithFrame:verticalScrollerFrame] autorelease]];
if (![[self horizontalScroller] isKindOfClass:[CRScroller class]])
[self setHorizontalScroller:[[[CRScroller alloc] initWithFrame:horizontalScrollerFrame] autorelease]];
}
- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
[self changeSubs];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
NSKeyedUnarchiver* unpacker = (id)aDecoder;
[unpacker setClass:[CRClipView class] forClassName:[NSClipView className]];
[unpacker setClass:[CRScroller class] forClassName:[NSScroller className]];
self = [super initWithCoder:aDecoder];
if (self)
{
}
return self;
}
- (void)awakeFromNib
{
[self changeSubs];
}
There are few tricks here, they work depending on a way NSScrollView is created. 'isKindOfClass' check helps to avoid double-swap.

Resources