cocoa objective c pdfview not loaded - cocoa

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.

Related

UINavigationController hides part of my view

I use storyboard, but want to load viewcontroller from xib file.
In storyboard I remove view.
Call to open viewcontroller:
- (void)SettingsButtonClick:(id)sender
{
CopyViewController* vc;
vc = [[CopyViewController alloc] initWithNibName:#"CopyViewController" bundle:nil];
[self.navigationController pushViewController:vc animated:YES];
}
But navigationcontroller hides part of my view. How can I arrange my View to start its frame below navigationcontroller?
self.view.frame = CGRectMake(0, 200, 100, 200); in viewDidLoad doesn't help me :-(
I have found solution
self.edgesForExtendedLayout = UIRectEdgeNone;

NSTextView inside NSTabviewItem, loading text delay

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.

How to add custom NSView to Window

I know how to do this in iOS but cannot figure it how to it in Cocoa.
I want to capture keyboard events and I think I need to override the acceptsFirstResponder method to accomplish that (keyDown method being triggered). So I created a class extending NSCustomView and tried to add it in the main Window but I just cannot understand how to do it. So far I added a Custom View to the main View then tried to add it programmatically like:
TestView *view = [[TestView alloc] init];
[[_window contentView] addSubview:view];
but this is not working. So how can I do this?
To see if the view has been added to a window, you can override the view's viewDidMoveToWindow method and log the value of [self window] to check (if it's nil then the view has been removed from a window):
- (void)viewDidMoveToWindow
{
NSLog(#"window=%p", [self window]);
[super viewDidMoveToWindow];
}
You should be subclassing NSView, not NSCustomView, and initWithFrame is the designated initializer for NSView, not init.
Try:
TestView *view = [[TestView alloc] initWithFrame:NSMakeRect(0, 0, 100, 200)];
[[_window contentView] addSubview:view];

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

Xcode - UILabel is not changing value on viewDidAppear

Hey everyone, I have a iPhone App I am creating. It uses a uitableview and that goes to a detail view.
Now on the detail view I have a scroll view, and all the data (XML) comes into it fine, each time, no issues.
My UILabels in my scrollview do update with the correct data, but, they keep adding subviews on top of each other to keep adding label after label and it all looks mumbo jumbo.
I have tried everything to try and remove the subviews such as:
for(UIView *subview in [scrollView subviews]) {
[subview removeFromSuperview];
}
AND
[[scrollView subviews] makeObjectsPerformSelector:#selector(removeFromSuperview)];
So I am stumped, I got no idea what is happening. Any help? I have been searching Google for ages and agesm, but keep finding the same answers that don't work :(
Any direction to sites that might help that you know of will be greatly appreciated.
Thanks!
Here is what I have in my controller that loads all the scrollview and labels:
- (void)viewDidAppear:(BOOL)animated {
// Create the scroll view for this view
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
scrollView.contentSize = CGSizeMake(320, 270);
[scrollView setFrame:CGRectMake(0, 198, 320, 170)];
// Do the labels for the text
UILabel *dates = [[UILabel alloc] initWithFrame:scrollView.bounds];
dates.textColor = [UIColor whiteColor];
dates.font = [UIFont boldSystemFontOfSize:12];
dates.text = round_date;
dates.tag = 1;
[dates setBackgroundColor:[UIColor clearColor]];
[dates setFrame:CGRectMake(10, 10, 280, 22)];
[scrollView addSubview:dates];
[dates release];
// Add the content to the main scrollview
[self.view addSubview:scrollView];
[scrollView release];
}
Ok, the reason for this is that viewDidAppear will get called every time you present the view.
If you do this is
-(void) viewDidLoad;
instead.
To make sure you can access them later you might want to keep a reference to them in your UIViewController
-(void) viewDidLoad {
scrollView = [[UIScrollView alloc] initWithFrame];
[self.view addSubview:scrollView];
}
and define it in your header file with:
UIScrollView *scrollView;

Resources