Detailed Implementation of private address book function, private address book Implementation
Private address book1. implement controller redirection Based on the segue object
// Go to the storyboard to find the corresponding line [self?mseguewithidentifier: @ "login" sender: nil] based on the ID of the seue object;
// Pass the value between controllers before the jump (downstream)
-(Void) prepareForSegue :( UIStoryboardSegue *) segue sender :( id) sender
{
SUNContactsController * contacts = seue. destinationViewController;
Contacts. navigationItem. title = self. accountF. text;
}
2. If there is no content in the input box, the logon button is disabled. There are two ways to do the first: [[nsnotificationcenterdefacenter] addObserver: selfselector: @ selector (textFieldChange) name: UITextFieldTextDidChangeNotificationobject: self. accountF];
[[Nsnotifcencenterdefacenter] addObserver: selfselector: @ selector (textFieldChange) name: UITextFieldTextDidChangeNotificationobject: self. pwdF];
-(Void) textFieldChange
{
Self. loginBtn. enabled = (self. accountF. text. length & self. pwdF. text. length );
}
// Remove notification-(void) dealloc from the dealloc Method
{
// Remove notification
[[Nsnotificationcenterdefacenter] removeObserver: self];
}
The second method is addTarget, because UITextField inherits UIControl [self. accountFaddTarget: selfaction: @ selector (textFieldChange) forControlEvents: UIControlEventEditingChanged];
[Self. pwdFaddTarget: selfaction: @ selector (textFieldChange) forControlEvents: UIControlEventEditingChanged];
-(Void) textFieldChange
{
Self. loginBtn. enabled = (self. accountF. text. length & self. pwdF. text. length );
}
Iii. Implementation of the logout button function-(IBAction) logout {
UIActionSheet * actionSheet = [[UIActionSheetalloc] initWithTitle: @ "deregister" delegate: selfcancelButtonTitle: @ "cancel" destructiveButtonTitle: @ "deregister" failed: nil, nil];
[ActionSheet showInView: self. view];
}
# Pragma mark-implement the Logout button function
-(Void) actionSheet :( UIActionSheet *) actionSheet clickedButtonAtIndex :( NSInteger) buttonIndex
{
If (buttonIndex = 0) {// remove the stack top Controller
[Self. navigationControllerpopToRootViewControllerAnimated: YES];
}
}
4. After the Controller jumps, the text box becomes the first responder-(void) viewDidAppear :( BOOL) animated
{
[Self. accountFbecomeFirstResponder];
}
Note: The viewDidAppear method indicates that the view display is complete (displayed in the window)
V. Redirect between controllers (inverse value transfer) // return to the contact list
[Self. navigationControllerpopViewControllerAnimated: YES]; // use a proxy to pass an object to Controller 5.1 first define a proxy @ protocolSUNAddContactsControllerDelegate <NSObject>
-(Void) addContactsController :( SUNAddContactsController *) addContactsController didContactsItem :( SUNContactsItem *) contactsItem;
@ End
5.2 then pass the object to the Controller
SUNContactsItem * contactsItem = [[SUNContactsItemalloc] init];
ContactsItem. account = self. account. text;
ContactsItem. pwd = self. pwd. text;
If ([self. delegaterespondsToSelector: @ selector (addContactsController: didContactsItem :)]) {
[Self. delegateaddContactsController: selfdidContactsItem: contactsItem];
}
5.3 method for implementing proxy in the Controller # pragma mark-proxy for implementing SUNAddContactsControllerDelegate
-(Void) addContactsController :( SUNAddContactsController *) addContactsController didContactsItem :( SUNContactsItem *) contactsItem
{
[Self. arrayMaddObject: contactsItem];
[Self. tableViewreloadData];
}
5.4 If two controllers jump between two controllers through the seue object, in the prepareforseue method, Judge-(void) prepareforseue :( UIStoryboardSegue *) seue sender :( id) sender
{
If ([segue. destinationViewControllerisKindOfClass: [SUNAddContactsControllerclass]) {
SUNAddContactsController * addContactsController = segue. destinationViewController;
AddContactsController. delegate = self;
}
}