I have 2 view controller: AccountViewController and ChangeEmailViewController. The account controller contains the email of the user. The user can change his email by pressing the button titled "change" and will take him to a ChangeEmailViewController. In ChangeEmailViewController, he can write the new email and click on the button titled "submit" to change the email and will show the new email in AccountViewController.(check image to see what I've done in storyboard)
image
My Questions are:
1- How I can connect both view controllers together?
2- How can I show the email of the user in the old email section in ChangeViewController?
3- How can I change the email of user in AccountViewController with the new email that the user will submit when he/she writes it in the textfield of ChangeEmailController and will be the new email in AccountViewController
Here are my answers
How I can connect both view controllers together?
You can use delegate. You can connect two viewcontrollers through delegate.
You can use NSNotificationCenter.
You can set one of them to a property of the other.
How can I show the email of the user in the old email section in ChangeViewController?
In general, you can pass the old email value when you call/create ChangeViewController. Perhaps, you will call/create instance of ChangeViewController via segue identification or Xib identification.
If you use segue identification, you can pass the value by overriding prepareForSeque.
please note: How to pass prepareForSegue: an object
If you use Xib identification, you can note below
Passing parameter from one xib to another xib
You could have another one way. If the value was stored in DB or BackEnd Server, you can get it again in ChangeViewController.
Of course, Once you think that it's better way for you.
How can I change the email of....
You can use Delegate or NSNotificationCenter.
When the value is changed, you can use call function through Delegate or send a message via NSNotificationCenter.
Well, if you have another questions, please feel free to contact me.
Thanks.
Related
I am trying to get a basic understanding of Cocoa Bindings and I would like to create a really simple project. I have a class Person which has a variable name of type NSString. Here is how I want things to work:
User enters a name into a text field and presses the "Update name" button
The string from the text field is saved to an instance of the Person class.
The label that is bound to the Person Controller (which is bound to the Person class) automatically changes its value according to the name variable of the Person instance.
I've spent hours reading various tutorials and the Apple Mac Developer Library, but each and every example only shows how to get Cocoa Bindings work with tables. When I try to develop something far more simpler I feel that I am completely lost. I have created a base project and the only thing left is to make all the bindings. I am kindly asking to make all the connections for me and hopefully provide me with an explanation. https://www.dropbox.com/sh/6hddfxyitqp6uoc/AACgaRhKBhLo6EXCVN9W6GQua?dl=0
The project is a document-based app because I will be developing an app of this type in the future.
There are several reasons why your project doesn't work so lets start again and create the simplest Cocoa Binding Example.
Create a new Xcode project, choose Cocoa Application and don't check "Use Storyboards", "Create Document-Based Application" or "Use Core Data".
Select MainMenu.xib, select the window and add a Text Field and a Label.
Add an Object Controller to the xib. Switch Prepares Content on.
Bind the Text Field to the Object Controller: bind Value to Object Controller, Controller Key selection and Model Key Path name.
Bind the Label to the Object Controller: bind Value to Object Controller, Controller Key selection and Model Key Path name.
Build, Run, Test. Enter some text and hit Return.
The controller automatically creates an instance of NSMutableDictionary which is KVO compliant for every key. When the contents of the Text Field is changed, the binding of the Text Field calls setValue:#"New Contents" forKey:#"name". This notifies the binding of the Label and the Label is updated.
Why your project doesn't work:
In the xib, the content of the Object Controller is connected to the document. The content of the controller should be a Person, not a Document. That's why you get [<Document 0x618000100750> valueForUndefinedKey:]: this class is not key value coding-compliant for the key name.. Remove this connection.
Class Person isn't KVO compliant. When the name changes, class Person doesn't emit a change notification and the binding doesn't notice the change. This can be fixed by using a property for name instead of an ivar. You don't have to use setValue:forKey: to change the name in code, person.name = [field stringValue] is ok.
The content of the Object Controller is set in the init method of the document. This is too early, the xib isn't loaded yet and the controller doesn't exist. Set the content in windowControllerDidLoadNib. Instead of addObject I would use setContent but addObject should work.
is there some way to deactivate FB share button or mark it like "done" after sharinig content? Like button have two states which indicates if I "like" it or not. On the share button is not visible if I shared the content or not. Is there a way to do it?
Thanks.
The only way i could think of is by authorizing a user with publish_actions. In that case, the response will be the new post id, as you can read in the docs: https://developers.facebook.com/docs/sharing/reference/share-dialog
BUT: You should not do something like that anyway. Let the user share stuff several times if he wants to. He may want to select different recipients for the share.
I am trying to build trival app in osx. I have made entity People with 3 fields: name, age and occupation. App is NOT document based.
ArrayController is binded with App Delegate in parameters section,and in the model key path, I have managedObjectContext
In the attributes inspector,as object controller I have entity name, and People as entity name.
Then I have binded the columns with the array controller, and as controller key I have arranged objects, and under model key path, I have name, age and occupation, (nstableview, has 3 columns).
On the end, I have 2 buttons, add and remove, which are connected with the array controller (add & remove respectively)
When I click on add button, empty record is created, I can edit it, and add the values. Remove button also works fine. But, when I close the app, and open it again, nothing seems to be preserved in core data.
I would like to mention at this point, that I didn't write single line of code so far, I am trying to do everything with binding.
Anyone can tell me what I missed to bind with what? I have searched stackoverflow and google, but I didn't manage to find any solution so far.
Regards, John
In case that anyone encounter the same issue...What I missed to do is connect save action with the table view...
(right click on app delegate and drag from save action to ns table view)
When i did that, problem has been solved, and my data is now saved.
In my MVC application, I dont want any user to type in the address bar of the browser and navigate to any controller action directly.Can I enable this for the whole application?if yes ,How? Can you please let me know the concept name ?
Also I dont want to do that through Request.URLReferrer because it has its own security risks (per Avoiding user to navigate to a view by entering url in the browser)
Thanks in advance!
You need to use Custom Action Filter Attributes, See :
http://www.asp.net/mvc/tutorials/hands-on-labs/aspnet-mvc-4-custom-action-filters
****Updated:**
As Parsanna mentioned in comment,
You can use the [ChildActionOnly] attribute on your action method to make sure it's not called directly, or use the ControllerContext.IsChildAction property inside your action to determine if you want to redirect.
See :Asp.net mvc How to prevent browser from calling an action method?
I have 2 action classes which share the same action form. I have defined the action form in request scope for both of them. Can you please tell me how to transfer this form object from 1st action to 2nd action.
I am avoiding sessions due to IE shares the same session across windows/tabs.
Employee Management app:
When admin edits an employee, it has 3 tabs. Personal, Education, Background.
Each tab represents a separate action class, which all share the common employeeForm action form class. So when admin is on Personal tab, it populates the employeeForm object with all the employee related data. Please tell me how to transfer this object from one tab to another, so that I dont hit the DB again.
Struts 1 or Struts 2?
If it's Struts 1.x, then you need to add <html:hidden> tags within the tab's <html:form>, for each of the properties you want to share between tabs.