Detailed Implementation of private address book function, private address book Implementation

Source: Internet
Author: User

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;
}
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.