last day (25 days later) » 

5:57 AM
0
A: Hide content view of NSApplication window in order to navigate to main screen

Nikolai NagornyConnect this method to the appropriate button or menu item - (IBAction)deliteAllSubviews:(id)sender { NSArray* views = [[window contentView]subviews]; for (NSView* view in views) { [view removeFromSuperview]; } }

 
This will remove all subviews of window.contentView. Just compare you view objects(you want to remove) and use removefrom superview.
 
Crash: <__NSArrayM: 0x608000242820> was mutated while being enumerated.
 
could you show your code?
 
Here is the code @Student :)
 
Add NSMutableArray *arrtoDelete = [views mutablecopy]; before your for loop and try again
 
5:57 AM
@Student As mentioned before, facing blank screen issue, i.e. I am not able to view my home screen(main window)
Pls
 
As my first comment. You have to place conditions in your for loop. Compare the view with your "_mainViewController.view" or with object of the view you want to delete). Then remove it.
 
Could u post the condition pls
-(IBAction)topicButton:(id)sender{
NSArray* views = [[[[AppDelegate sharedAppDelegate]window] contentView]subviews];
NSMutableArray *viewsToDelete = [views mutableCopy];
for (NSView *subView in viewsToDelete) {
if ([subView isEqualTo:[ModelClass sharedInstance].mainViewController.view]) {
[subView removeFromSuperview];
}
}
}
even then the screen is blank
actually through debugging I found that if condition is not valid
 
As your code link
This condition is correct. if([subView isEqualTo:_mainViewController.view]){}
 
6:12 AM
But the condition fails, checked through debugging
And wonder why the screen becomes blank if the condition is failing
as the subview is removed from superview upon condition success
 
1.. Check you are adding the same object which you are intended to remove.
2.. Check that object in SubView array

right, screen should not be blank, if condition fails.
Use this once --

-(void)addViewToWindow:(NSView *)customView
{
[self.window.contentView addSubview:customView];
}

-(IBAction)navigateToLesson:(id)sender
{
if(! self.mainViewController)
{
self.mainViewController = [[CoreViewController alloc]initWithNibName:@"ChapterView" bundle:nil];
[[AppDelegate sharedAppDelegate] addViewToWindow:_mainViewController.view];
}
}

//Navigation to home screen(main window)
-(IBAction)topicButton:(id)sender
{
NSMutableArray* views = [[[[[AppDelegate sharedAppDelegate]window] contentView]subviews]mutablecopy];
 
Same blank screen issue again without condition success :(
 
6:28 AM
As i think this code has no error. May be you are doing something wrong in your real code.
 
Actually I logged views array and found the contents of CoreViewController(window's content view) in console, i.e.
"<NSImageView: 0x60800017a940>",
"<NSButton: 0x608000145540>",
"<NSButton: 0x608000145800>",
"<NSButton: 0x6080001458b0>",
"<NSButton: 0x608000145960>",
"<NSButton: 0x608000145a10>",
"<NSButton: 0x608000145ac0>",
"<NSButton: 0x608000145b70>",
"<NSButton: 0x608000145c20>",
"<NSButton: 0x608000145cd0>",
"<NSButton: 0x608000145d80>",
"<NSButton: 0x608000145e30>",
"<NSImageView: 0x60000017b480>",
"<NSButton: 0x600000145800>",
"<NSView: 0x608000129420>"
But wonder why the condition is failing and also if the content view is hidden or removed, we should see the main window content,right....but definitely not the blank screen :|
 
Its right you have 2 imageview + some buttons + one view in window.contentview currently. U have to remove that NSView from window. Are you sure you are passing same view in if condition?
You can not hide the contentview of any window. Just you can hideits subviews
 
Yeah, I am not able to hide its sub views
I mean window's content view sub views
 
6:48 AM
what this line means - [[AppDelegate sharedAppDelegate]window] in your code.
 
In my app delegate file, I have this class method
+(AppDelegate *)sharedAppDelegate
{
if (!sharedAppDelegate) {
sharedAppDelegate = (AppDelegate *)[[NSApplication sharedApplication]delegate];
}
return sharedAppDelegate;
}
through that I would access my main window
 
Is "if (!sharedAppDelegate)" condition is right? Because i think "sharedAppDelegate" is ur method name.
 
static AppDelegate *sharedAppDelegate;
declared in our app delegate main file
 
Can you change this method name. (If its feasable to ur code)
 
I changed it as follows
+(AppDelegate *)sharedInstanceofAppDelegate
{
if (!sharedAppDelegate) {
sharedAppDelegate = (AppDelegate *)[[NSApplication sharedApplication]delegate];
}
return sharedAppDelegate;
}
 
6:57 AM
Now check again
 
7:10 AM
Same blank screen again, what else should I do...I also created a reference view in app delegate, then passed our content view to it
[self.window.contentView addSubview:self.saralapadani.mainViewController.view];
[self setReferenceView:_mainViewController.view];
Now tried to remove subview from content view
-(IBAction)topicButton:(id)sender
{
NSMutableArray* views = [[self.window.contentView subviews] mutableCopy];
NSLog(@"views contents are %@",views);
for (NSView* myView in views) {
if([myView isEqualTo:_referenceView]){
[myView setHidden:YES];
}
}
}
 
"topicButton:" method is in appdelegate?
 
No it is in the respective lesson view, the actual method is
-(IBAction)topicButton:(id)sender{
[[AppDelegate sharedInstanceofAppDelegate] enableMainMenuAndHideContent];
}
the enableMainmenuAndHideContent contains all the stuff of removing subview
 
if([myView isEqualTo:_mainViewController.view]){ }
I mean in my code "mainViewController" object should be declaired in the same class where the container method is getting called. Otherwise you have to use "yourclassnameObj.mainViewController.view"
 
7:37 AM
Let me make myself clear first, for the buttons in main menu, i.e. navigating to mainViewController, I am declaring the method in app delegate itself. Using a model class called ModelClass, I wrote all the stuff related to mainView i.e. contents in image view, buttons etc. and through which I try to navigate user to respective lesson,

-(IBAction)navigateToLesson:(id)sender
{
NSButton *selectedButton = (NSButton *)sender;
NSInteger tagValue = selectedButton.tag;
self.reference = [Reference sharedInstance];
 
7:49 AM
make a method in the same class in which "navigateToLession()" is written. And call it in topicButton() method .

-(void)removeTheView:(id)sender
{
NSMutableArray* views = [[self.window.contentView subviews]mutablecopy];

for (NSView* myview in views) {
if([myView isEqualTo:self.saralapadani.mainViewController.view]){
[myview setHidden];
}
}
 
-(void)removeTheView:(id)sender
{
self.saralapadani = [ModelClass sharedInstance];
NSMutableArray* views = [[self.window.contentView subviews] mutableCopy];

for (NSView* myview in views) {
if([myview isEqualTo:self.saralapadani.mainViewController.view]){
[myview setHidden:YES];
}
}
}


in app delegate, then in main view controller....I am accessing the method in my topic button action
-(IBAction)topicButton:(id)sender{
[[AppDelegate sharedInstanceofAppDelegate] removeTheView:sender];
}
Again the same blank screen issue :(
Feeling bad that I am testing ur patience :x
 
No problem. its a simple query. Don't know whats the problem is.

delete "self.saralapadani = [ModelClass sharedInstance]; " line in removetheview method. because u have used it once earlier in "navigateToLesson". Its content may be a cause.
 
8:14 AM
Doesn't make much difference, still the same blank screen :(
 
8:36 AM
I tried this way as well
-(void)removeTheView:(id)sender
{
NSMutableArray* views = [[self.window.contentView subviews] mutableCopy];
self.saralapadani.mainViewController = [[CoreViewController alloc]initWithNibName:@"ChapterView" bundle:nil];

for (NSView* myview in views) {
if([myview isEqualTo:self.saralapadani.mainViewController.view]){
[myview setHidden:YES];
}
}
}
now there is no blank screen/navigation to home view, but crash at autorelease pool
 

  last day (25 days later) »