IBOutlet inside document based application - nsdocument

I've created an application document based but I had problem to handle IBOutlet becouse when I selected some controller inside the document in the first window sometime the other same controller in another window document was selected too...
Maybe I did wrong with strong/weak/readwrite or something I'm not very sure so I've decided to force my application to have just one window document for time.
Now my problem. I've an arrayController and when I launch my application and I do open saved file it close the "blank document" created by default and show the new window document with the data loaded.
The problem is that the arrayController of the second window called inside the windowControllerDidLoadNib is the right pointer (created by makeWindowControllers) but when I use this inside the code it has another pointer that is the old arrayController of the blank document that is been closed!! Why? Do close method release everything? (I use ARC).
Excuse me if my words are confused, I'm newbie. Thank you.
This is my code:
Document* newDoc = [[Document alloc] init];
[[NSDocumentController sharedDocumentController]addDocument:newDoc];
[newDoc makeWindowControllers];
[newDoc showWindows];

I've solved this issue: when you define notification for some object as a nsdocument these are not released after close calls. So you need to remove observer!

Related

#SetViewInfo - Issue when clearing filter

I have a problem that have me stumped.
I have been searching for a solution, but haven't found a working one yet. The solutions I seen introduces other issues.
Here is the scenario:
I have a frameset with two frames: 'Navigator' and 'Main'.
In the 'Navigator' frame I display a form called 'Navigator'. It contains an outline, to display a menu.
In the 'Main' frame I display the view selected by the user in the navigator.
So this is a very traditional Notes client application.
I now want to add a checkbox at the top of the view (in the action bar), allowing the user to filter the view by his/her own name. I use #SetViewInfo for this, and it all works perfect.
The issue is when the user switch views. The #SetViewInfo filter stays active when switching to a different view, so after some searching I found some solutions:
In http://www-01.ibm.com/support/docview.wss?uid=swg21204481 IBM suggests to put the following code in the QuerySave event:
#SetViewInfo([SetViewFilter]; temp ; 0 ;1)
When I am switching view or closing the view, I get the error message "Cannot execute the specified command".
In http://www-10.lotus.com/ldd/bpmpblog.nsf/dx/using-setviewinfo-in-a-notes-client-application-to-create-a-user-specific-view Andre Guirard suggests to put the following code in the QuerySave event:
#SetTargetFrame("frameName");
#UpdateFormulaContext;
#Command([OpenView]; #Subset(#ViewTitle; -1));
#SetViewInfo([SetViewFilter]; ""; "columnName"; 1)
I modify this to match my frame name and the programatic name of the first column in my view:
#SetTargetFrame("Main");
#UpdateFormulaContext;
#Command([OpenView]; #Subset(#ViewTitle; -1));
#SetViewInfo([SetViewFilter]; ""; "Adjuster"; 1)
This works perfectly when switching between view. But when I close the application while I am in this particular filtered view, the application is re-opened automatically. This happens no matter if the filter is enabled or not when closing the view.
However, when the view repopens, the frameset is not reloaded, it is just the view with the built-in view navigator to the left.
I finally got this to work by (in the built-in view navigator) selecting another view that the one where I filter data. This fixed the issue for a while, but then it starts again, and the filtered view is active in the navigator.
Obviously it is the OpenView command that is causing this, but if I remove just that line, I get the "Cannot execute the specified command" error again.
Any suggestions/pointers? I am using Notes 8.5.3 running on Windows 7 Professional.
This question can also be found in the IBM developerWorks forum for Notes 8.5:
http://www-10.lotus.com/ldd/nd85forum.nsf/DateAllThreadedWeb/08c73910571306c485257b2b0061ef91
First thing, I would suggest to make sure your view frame is always called "NotesView". You will have much less compatibility issues if you do this.
Secondly, I presume when you say you put it in the QuerySave event you really mean the QueryClose event? Views do not have a QuerySave event.
Thirdly, I find the #UpdateFormulaContext line is not needed. This is what I have in my view QueryClose...
#SetTargetFrame("NotesView");
#Command([OpenView]; #Subset(#ViewTitle; -1));
#SetViewInfo([SetViewFilter]; ""; "<programmaticColumnName>"; 1)
And I can close the app while in the view without any problems.

Receiver has no segue with identifier

I have a problem that I've been sitting with all the day. I have a super view which contains UIPageControl and UIScrollView, in this super view. I have created a sub view which contains three images, three labels, and three buttons. Each button has a touch up event. When the button event is triggered the super view will be promoted by a new view. For doing that, I created a segue which connected with super view and new view. Here is the connection code in the super view.
`
<connections>
<outlet property="pageControl" destination="ivy-0Q-UQo" id="rGm-sh-mdE"/>
<outlet property="scrollView" destination="4Yu-Qb-kbF" id="aqY-ou-cv4"/>
<segue destination="zZo-CH-P2Y" kind="push" id="xBU-ZO-u7s"/>
</connections>
`
This piece of code will guarantee the connection between the super view and the new view is okay,
here is the touch up event code.
WelcomeFrameViewController *welcomeFrameVC = [WelcomeFrameViewController alloc]; //super view instance
NSLog(#"=======================");
[welcomeFrameVC performSegueWithIdentifier: #"ForwardToLogin" sender: self];
When I run the program, the compiler complains with
2012-08-20 10:17:02.325 TTRen[2440:f803] ============44===========
2012-08-20 10:17:02.352 TTRen[2440:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver WelcomeFrameViewController: 0x688e960 has no segue with identifier 'ForwardToLogin''
I am quite new in iOS, any suggestions will be deeply appreciated.
'Receiver WelcomeFrameViewController: 0x688e960 has no segue with
identifier 'ForwardToLogin''
In your storyboard, check that you actually have a segue named "ForwardToLogin"
There does seem to be a bug with xCode (still in 6) where storyboard changes you make aren't get copied to the simulator. You can reset the Simulator's Content & Settings to resolve this.
Other things to check:
Check the naming of your segue. Check it again. Check it some more :-)
Ensure that your segue is pointing in the right direction. It needs to point away from the UIViewController that calls performSegue….
Ensure you don't have two copies of your view controller on top of each other, with the segue attached to the one on top, and you instantiating the one underneath!
There's a similar question here and I encountered the same problem too. The reset fixed it for me.

Core Data can't save anything

I have started learning Core Data programming and I have a problem. The book that helped me in my studies is written for XCode3, and I'm using XCode4. I surfed on the Net and found this article . I've done everything just like it's written there and created my entity just like it's written in the book. To enable the save action I was told to CTRL+drag the Save menu item to the AppDelegate in my nib. I did so, but when I make changes in the program and then save it when I reopen it it seems that nothing has saved. How could I solve this?
Thanks in advance.
You need to connect save button with an action handler. It must have this structure:
.h file
#interface YourClass : UITableViewController
//... ivars, properties
-(IBAction)saveButtonPressed:(id)sender;
#end
.m file
-(void)saveButtonPressed:(id)sender {
[self.managedObjectContext save:nil];
}
Now the ctrl-dragging should work. Drag from the button to the controller. In the resulting black popup you should be able to select saveButtonPressed.
Edit
An even better method is to do this: open the split view controller. On the left you have your storyboard / IB with button, on the right the .h file of your view controller class. Now control drag from the button to a space above #end in the .h file. In the popup, select "Action" (not "Outlet"), name it e.g. saveButtonPressed. Press OK and Xcode will generate automatically all of the above. Now just fill in the save instruction in your new button handler.

Creating a new NSManagedObject within an NSPersistentDocument refuses to save even though undo shows as possible

I have a CoreData / NSPersistentDoc app. It works fine.
I added a new entity to the MOM, and updated the version.
Now, when I create new instances of that Entity inside the MOC, the "Save" menu item remains disabled until/unless I create any instances of the old Entities that were already in the app.
The red dot button on titlebar correctly goes black to show that the document has changed - but OS X / NSDocument refuses to acknowledge this - it is impossible to do a Save.
Any ideas?
I found the cause / solution - it was my own bug, but this answer may help others with similar issues.
I was using Apple's official approach for enabling the Copy/Paste menu items (by implementing validateMenuItem), and returning true/false for copy and paste at the right times.
And I was returning NSPersistentDocument's implementation for everything else (which included Save, although I didn't see that).
Then, when I added my new NSManagedObject, I added a sub-view, and sub-view-controller, and I delegated the validateMenuItem to this - i.e. so that it could handle it's own copy/paste status.
...but I had no code path for "if it's not copy paste, and it's not handled by the child, and it's not handled by my NSPersistenDocument subclass ... then hand it to NSPersistentDocument to decide"...
...and so the Save menuitem was never being enabled.

'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name

I have a window based applicaiton with tab bar and navigation bar integrated into it. On the navigation bar have a custom button which opens a table view.
On clicking on the cell of the table I want to open a new table view controller. But as soon as I click on the cell of first table I get an exception that
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'AddForm''
I have checked that AddForm is in right place.
I have tried all the solutions given above and on other thread, but still stuck. I hope someone can help me.
The flow is something like this
ListButton (on click opens a list view) -> a table view opens -> (on click of a cell should open a new table view Controller and fetch data from core data)
My root view controller code is in the second table view controller file... is that what I am doing wrong? I am doing so because I don't need the core data before that....
Please help
Thanks in advance
I Used to have the same problem first of all check in your AppDelegate.m class if the managedObjectContext is created
if it is created check if it is pass it as argument
something like this
MasterViewController *controller = (MasterViewController *)masterNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
if that is correct for you main view just be sure that you are passing it through your views something like this
self.detailViewController.managedObjectContext = self.managedObjectContext;
well at least that works for me =)
The most common cause of this problem is misspelling the name of the entity or getting the capitalization wrong. Check that AddForm is spelled exactly the same in the code and the data model editor.

Resources