UITextFieldDelegate

UITextFieldDelegate委托方法注释:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{ 
    //返回一个BOOL值,指定是否循序文本字段开始编辑 
    return YES; 
 
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    //开始编辑时触发,文本字段将成为first responder
}
 
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    //返回BOOL值,指定是否允许文本字段结束编辑,当编辑结束,文本字段会让出first responder
    //要想在用户结束编辑时阻止文本字段消失,可以返回NO
    //这对一些文本字段必须始终保持活跃状态的程序很有用,比如即时消息
    return NO;
}
 
- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    //当用户使用自动更正功能,把输入的文字修改为推荐的文字时,就会调用这个方法。
    //这对于想要加入撤销选项的应用程序特别有用
    //可以跟踪字段内所做的最后一次修改,也可以对所有编辑做日志记录,用作审计用途。  
    //要防止文字被改变可以返回NO
    //这个方法的参数中有一个NSRange对象,指明了被改变文字的位置,建议修改的文本也在其中
    return YES;
}
- (BOOL)textFieldShouldClear:(UITextField *)textField{
    //返回一个BOOL值指明是否允许根据用户请求清除内容
    //可以设置在特定条件下才允许清除内容
    return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
    //返回一个BOOL值,指明是否允许在按下回车键时结束编辑
    //如果允许要调用resignFirstResponder 方法,这回导致结束编辑,而键盘会被收起
    [textField resignFirstResponder];//查一下resign这个单词的意思就明白这个方法了
    return YES;
}
整理SDNQuickSetupSetControllerInfoViewController的逻辑,找到与isAgreePrivacyPolicyOn与进入next的按钮相关的逻辑,并告诉我该怎么改? // // SDNQuickSetupSetControllerInfoViewController.h // Omada // // Created by PengXiaochuang on 2020/1/2. // Copyright © 2020 TP-Link. All rights reserve∂d. // #import "SDNQuickSetupBasicFrameViewController.h" #import "TPSDNTimeZoneInfoTool.h" NS_ASSUME_NONNULL_BEGIN @interface SDNQuickSetupSetControllerInfoViewController : SDNQuickSetupBasicFrameViewController @property (nonatomic, strong, readonly) NSString* countrollerName; @property (nonatomic, strong, readonly) NSString* selectedCountryName; @property (nonatomic, strong, readonly) NSString* selectedCountryKey; @property (nonatomic, strong, readonly) NSString* selectedTimezoneName; @property (nonatomic, strong, readonly) TPSDNTimeZoneItem* selectedTimeZoneItem; @property (nonatomic, assign, readonly) BOOL isAgreePrivacyPolicyOn; @property (nonatomic, assign, readonly) BOOL isAgreeUeipOn; -(void)gotoSelectCountryPage; -(void)gotoSelectTimezonePage; //-(void)gotoAgreementPage; @end NS_ASSUME_NONNULL_END // // SDNQuickSetupSetControllerInfoViewController.m // Omada // // Created by PengXiaochuang on 2020/1/2. // Copyright © 2020 TP-Link. All rights reserved. // #import "SDNQuickSetupSetControllerInfoViewController.h" #import "TPInputGroupView.h" #import "TPInputCheckTool.h" #import "TPSelectionGroupView.h" #import "TPSDNCountryInfoTool.h" #import "TPSDNTimeZoneInfoTool.h" #import "SDNQSSelectCountryTableViewController.h" #import "SDNQSSelectTimeZoneTableViewController.h" #import "ALSDNQuickSetup.h" #import "PrivacyPolicyViewController.h" #import "TermsOfServiceViewController.h" #import "UserExperienceImprovementProgramViewController.h" @interface SDNQuickSetupSetControllerInfoViewController ()<UITextFieldDelegate, TTTAttributedLabelDelegate, SDNQuickSetupSelectionTableViewControllerDelegate> @property(nonatomic, strong)TPInputGroupView *nameGroupView; @property(nonatomic, strong)TPSelectionGroupView *countryGroupView; @property(nonatomic, strong)TPSelectionGroupView *timezoneGroupView; @property (nonatomic, assign) BOOL isSupportedAgreePrivacyPolicy; @property (nonatomic, assign) BOOL isSupportedAgreeUeip; //4.2新增用户展示同意隐私政策Button @property (nonatomic, strong) UIButton *agreePrivacyPolicyButton; @property (nonatomic, assign, readwrite) BOOL isAgreePrivacyPolicyOn; @property (nonatomic, strong) TTTAttributedLabel *agreePrivacyPolicyLabel; //4.2新增用户是否同意参加体验计划Button @property (nonatomic, strong) UIButton *agreeUeipButton; @property (nonatomic, assign, readwrite) BOOL isAgreeUeipOn; @property (nonatomic, strong) TTTAttributedLabel *agreeUeipLabel; @property (nonatomic, strong, readwrite) NSString* selectedCountryName; @property (nonatomic, strong, readwrite) NSString* selectedCountryKey; @property (nonatomic, strong, readwrite) NSString* selectedTimezoneName; @property (nonatomic, strong, readwrite) TPSDNTimeZoneItem* selectedTimeZoneItem; @end @implementation SDNQuickSetupSetControllerInfoViewController - (instancetype)init { self = [super init]; if (self) { self.xTitle = gSDNQuickSetup.setupWizardTitle; self.xIsNeedShowPageControl = YES; self.xSubTitle = @""; self.xNextText = gSDNGlobal.next; self.selectedTimeZoneItem = [[TPSDNTimeZoneItem alloc] init]; self.selectedCountryKey = @""; self.selectedCountryName = @""; self.selectedTimezoneName = @""; self.isSupportedAgreePrivacyPolicy = TPSDNControllerClient.currentInstance.termsAndPolicyComponent.isSupported; self.isSupportedAgreeUeip = TPSDNControllerClient.currentInstance.explmproveComponent.isSupported; } return self; } - (void)viewDidLoad { [super viewDidLoad]; [self requestDataFromNetwork]; [self.pageControl setCurrentPage:0]; } - (void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; if (self.agreePrivacyPolicyButton) { self.agreePrivacyPolicyButton.accessibilityFrame = [TPBA11yHelper getEnlargedAccessibilityFrame:self.agreePrivacyPolicyButton]; } if (self.agreeUeipButton) { self.agreeUeipButton.accessibilityFrame = [TPBA11yHelper getEnlargedAccessibilityFrame:self.agreeUeipButton]; } } -(void)setupNav { [super setupNav]; } -(BOOL)checkQuickSetupSDNControllerName:(NSString*)name { if (![[TPSDNControllerClient currentInstance].systemComponent.controllerInfo isVersionLowerThanV5]) { return [TPInputCheckTool checkQuickSetupSDNControllerNameV3:name]; } else if ([[TPSDNControllerClient currentInstance].systemComponent.controllerInfo isVersionLowerThanV5]) { return [TPInputCheckTool checkQuickSetupSDNControllerName:name]; } else { return [TPInputCheckTool checkQuickSetupSDNControllerNameV2:name]; } } - (void)setupSubViews { [super setupSubViews]; [self.nextButton setEnabled:NO]; self.nextButton.hidden = NO; TPWeakSelf; TPInputGroupView *nameGroupView = [[TPInputGroupView alloc] initForUnderlineTextFieldWithInitBlock:^( TPInputGroupView * groupContentView, UILabel * titleLabel, TPUnderLineTextField* valueFiled, UILabel * tipsLabel, UILabel * errorLabel){ TPStrongSelf; titleLabel.text = gSDNGlobal.controllerName; valueFiled.returnKeyType = UIReturnKeyDefault; valueFiled.delegate = _self; valueFiled.text = @""; if ((![[TPSDNControllerClient currentInstance].systemComponent.controllerInfo isVersionLowerThanV5])) { valueFiled.keyboardType = UIKeyboardTypeDefault; }else{ valueFiled.keyboardType = UIKeyboardTypeASCIICapable; } }]; if (nameGroupView) { [nameGroupView updateUIStyle]; [nameGroupView tpbConfigAsTopCardStyle]; [self.frameView addSubview:nameGroupView]; [nameGroupView updateOnFocusBlock:^( TPInputGroupView * groupContentView, UILabel * titleLabel, TPUnderLineTextField* valueFiled, UILabel * tipsLabel, UILabel * errorLabel){ TPStrongSelf; // 监控状态焦点 [groupContentView changeToNormalState]; }]; [nameGroupView updateOnUnfocusBlock:^( TPInputGroupView * groupContentView, UILabel * titleLabel, TPUnderLineTextField* valueFiled, UILabel * tipsLabel, UILabel * errorLabel){ TPStrongSelf; //非焦点状态,一般用于检查 输入的内容是否合法 // 需要把文案首尾去除空白 NSString *name = valueFiled.text; name = [name stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; valueFiled.text = name; if([self checkQuickSetupSDNControllerName:valueFiled.text]) { [groupContentView changeToNormalState]; } else { if (IsEmptyString(valueFiled.text)) { [groupContentView changeToWarningStateWithErrorMessage:gSDNQuickSetup.checkRequiredControllerName]; } else { [groupContentView changeToWarningStateWithErrorMessage:gSDNQuickSetup.checkControllerNameError]; } } [_self updateNextButtonStatus]; }]; [nameGroupView updateOnValueChangedBlock:^( TPInputGroupView * groupContentView, UILabel * titleLabel, TPUnderLineTextField* valueFiled, UILabel * tipsLabel, UILabel * errorLabel){ // 刻检查内容是否合法并修正 TPStrongSelf; [_self updateNextButtonStatus]; }]; [nameGroupView mas_makeConstraints:^(MASConstraintMaker *make) { TPStrongSelf; make.leading.equalTo(_self.frameView).offset(16); make.trailing.equalTo(_self.frameView).offset(-16); make.top.equalTo(_self.frameView); }]; self.nameGroupView = nameGroupView; } TPSelectionGroupView *countryGroupView = [[TPSelectionGroupView alloc] init]; if (countryGroupView) { [countryGroupView updateUIStyle]; [self.frameView addSubview:countryGroupView]; if ([[TPSDNControllerClient currentInstance].quickSetupComponent supportForComponent:DMSDNComponentIDMsp ForVersionCode:1]) { [countryGroupView updateSelectedKeyWithText:gMeshQuickSetup.sdnCountryOrRegion]; } else { [countryGroupView updateSelectedKeyWithText: gSDNGlobal.countryOrRegion]; } [countryGroupView updateSelectedValueWithText: gSDNGlobal.pleaseSelect]; [countryGroupView updateValueWithSelectedState:NO]; TPWeakSelf; [countryGroupView addSelectedBlock:^{ TPStrongSelf; DDLogDebug(@"进入选择国家列表"); [_self gotoSelectCountryPage]; }]; [countryGroupView mas_makeConstraints:^(MASConstraintMaker *make) { TPStrongSelf; make.leading.trailing.equalTo(_self.nameGroupView); make.top.equalTo(nameGroupView.mas_bottom); }]; self.countryGroupView = countryGroupView; } TPSelectionGroupView *timezoneGroupView = [[TPSelectionGroupView alloc] init]; if (timezoneGroupView) { [timezoneGroupView updateUIStyle]; [timezoneGroupView tpbConfigAsBottomCardStyle]; [self.frameView addSubview:timezoneGroupView]; if ([[TPSDNControllerClient currentInstance].quickSetupComponent supportForComponent:DMSDNComponentIDMsp ForVersionCode:1]) { [timezoneGroupView updateSelectedKeyWithText:gMeshQuickSetup.sdnTimezone]; } else { [timezoneGroupView updateSelectedKeyWithText:gSDNGlobal.timezone]; } [timezoneGroupView updateSelectedValueWithText: gSDNGlobal.pleaseSelect]; [timezoneGroupView updateValueWithSelectedState:NO]; TPWeakSelf; [timezoneGroupView addSelectedBlock:^{ TPStrongSelf; DDLogDebug(@"进入选择区列表"); [_self gotoSelectTimezonePage]; }]; [timezoneGroupView mas_makeConstraints:^(MASConstraintMaker *make) { TPStrongSelf; make.leading.trailing.equalTo(_self.countryGroupView); make.top.equalTo(countryGroupView.mas_bottom); if (!_self.isSupportedAgreePrivacyPolicy && !_self.isSupportedAgreeUeip) { make.bottom.equalTo(_self.frameView); } }]; self.timezoneGroupView = timezoneGroupView; } if (self.isSupportedAgreePrivacyPolicy) { UIButton *agreePrivacyPolicyButton = [[UIButton alloc] init]; if (agreePrivacyPolicyButton) { [self.frameView addSubview:agreePrivacyPolicyButton]; self.agreePrivacyPolicyButton = agreePrivacyPolicyButton; self.isAgreePrivacyPolicyOn = NO; [self updateAgreePrivacyPolicyButtonImage]; [agreePrivacyPolicyButton addTarget:self action:@selector(didTapAgreePrivacyPolicyButton) forControlEvents:UIControlEventTouchUpInside]; TPWeakSelf; [agreePrivacyPolicyButton mas_makeConstraints:^(MASConstraintMaker *make) { TPStrongSelf; make.width.height.mas_equalTo(24); make.leading.equalTo(_self.nameGroupView); make.top.equalTo(timezoneGroupView.mas_bottom).offset(20); }]; agreePrivacyPolicyButton.accessibilityLabel = [gAccount.sdnAcceptPolicyText replaceFormatPlaceHolders:@[ gSDNQuickSetup.agreeTermsOfUseLinkText,gSDNQuickSetup.agreePrivacyPolicyLinkText]]; self.agreePrivacyPolicyButton = agreePrivacyPolicyButton; } TTTAttributedLabel *agreePrivacyPolicyLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero]; if (agreePrivacyPolicyLabel) { [self.frameView addSubview:agreePrivacyPolicyLabel]; agreePrivacyPolicyLabel.isAccessibilityElement = YES; agreePrivacyPolicyLabel.delegate = self; agreePrivacyPolicyLabel.textColor = [UIColor tpbTextSecondaryContent]; agreePrivacyPolicyLabel.tpbDynamicFont = [UIFont tpr14Regular]; agreePrivacyPolicyLabel.lineBreakMode = NSLineBreakByWordWrapping; agreePrivacyPolicyLabel.textAlignment = NSTextAlignmentLeft; agreePrivacyPolicyLabel.numberOfLines = 0; agreePrivacyPolicyLabel.linkAttributes = @{NSForegroundColorAttributeName:[UIColor tpbTextLink]}; agreePrivacyPolicyLabel.activeLinkAttributes = @{NSForegroundColorAttributeName:[UIColor tpbTextLinkHover]}; NSString *termsStr = [TPBA11yHelper transToNOBreakStr:gAccount.accountTermsOfUse]; NSString *policyStr = [TPBA11yHelper transToNOBreakStr:gSDNQuickSetup.agreePrivacyPolicyLinkText]; NSString *fullText = [gAccount.sdnAcceptPolicyText replaceFormatPlaceHolders:@[ termsStr,policyStr]]; agreePrivacyPolicyLabel.text = fullText; NSDictionary *linkDict = @{@"target": termsStr}; [agreePrivacyPolicyLabel addLinkToTransitInformation:linkDict withRange: [fullText rangeOfString:termsStr]]; linkDict = @{@"target": policyStr}; [agreePrivacyPolicyLabel addLinkToTransitInformation:linkDict withRange: [fullText rangeOfString:policyStr]]; TPWeakSelf; [agreePrivacyPolicyLabel mas_makeConstraints:^(MASConstraintMaker *make) { TPStrongSelf; make.top.equalTo(agreePrivacyPolicyButton); make.leading.equalTo(agreePrivacyPolicyButton.mas_trailing).offset(6); make.trailing.equalTo(_self.nameGroupView); make.height.greaterThanOrEqualTo(agreePrivacyPolicyButton); if (!_self.isSupportedAgreeUeip) { make.bottom.equalTo(_self.frameView); } }]; self.agreePrivacyPolicyLabel = agreePrivacyPolicyLabel; } } if (self.isSupportedAgreeUeip) { UIButton *agreeUeipButton = [[UIButton alloc] init]; if (agreeUeipButton) { [self.frameView addSubview:agreeUeipButton]; self.agreeUeipButton = agreeUeipButton; self.agreeUeipButton.hidden = self.coordinator.ecDevice.isCloudBasedController; self.isAgreeUeipOn = NO; [self updateAgreeUeipButtonImage]; [agreeUeipButton addTarget:self action:@selector(didTapAgreeUeipButton) forControlEvents:UIControlEventTouchUpInside]; TPWeakSelf; [agreeUeipButton mas_makeConstraints:^(MASConstraintMaker *make) { TPStrongSelf; make.width.height.mas_equalTo(24); make.leading.equalTo(_self.nameGroupView); if (_self.isSupportedAgreePrivacyPolicy) { make.top.equalTo(_self.agreePrivacyPolicyLabel.mas_bottom).offset(16); } else { make.top.equalTo(timezoneGroupView.mas_bottom).offset(20); } }]; agreeUeipButton.accessibilityLabel = [gPrivacyAndTermsOfUse.policyUEIP replaceFormatPlaceHolders:@[gSDNQuickSetup.agreeUeipLinkText]]; self.agreeUeipButton = agreeUeipButton; } TTTAttributedLabel *agreeUeipLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero]; if (agreeUeipLabel) { [self.frameView addSubview:agreeUeipLabel]; agreeUeipLabel.delegate = self; agreeUeipLabel.textColor = [UIColor tpbTextSecondaryContent]; agreeUeipLabel.tpbDynamicFont = [UIFont tpr14Regular]; agreeUeipLabel.lineBreakMode = NSLineBreakByWordWrapping; agreeUeipLabel.textAlignment = NSTextAlignmentLeft; agreeUeipLabel.numberOfLines = 0; agreeUeipLabel.isAccessibilityElement = YES; agreeUeipLabel.linkAttributes = @{NSForegroundColorAttributeName:[UIColor tpbTextLink]}; agreeUeipLabel.activeLinkAttributes = @{NSForegroundColorAttributeName:[UIColor tpbTextLinkHover]}; NSString *fullText = [gPrivacyAndTermsOfUse.policyUEIP replaceFormatPlaceHolders:@[gSDNQuickSetup.agreeUeipLinkText]]; agreeUeipLabel.text = fullText; NSDictionary *linkDict = @{@"target": gSDNQuickSetup.agreeUeipLinkText}; [agreeUeipLabel addLinkToTransitInformation:linkDict withRange: [fullText rangeOfString:gSDNQuickSetup.agreeUeipLinkText]]; TPWeakSelf; [agreeUeipLabel mas_makeConstraints:^(MASConstraintMaker *make) { TPStrongSelf; make.top.equalTo(agreeUeipButton); make.leading.equalTo(agreeUeipButton.mas_trailing).offset(6); make.trailing.equalTo(_self.nameGroupView); make.height.greaterThanOrEqualTo(agreeUeipButton); make.bottom.equalTo(_self.frameView); }]; self.agreeUeipLabel = agreeUeipLabel; self.agreeUeipLabel.hidden = self.coordinator.ecDevice.isCloudBasedController; } } [self updateNextButtonStatus]; } -(void)requestDataFromNetwork { DMSDNQuickSetupInfo *quickSetupInfo = [TPSDNControllerClient currentInstance].quickSetupComponent.quickSetupInfo; if (IsEmptyString(quickSetupInfo.controllerName)) { [self showWaitingToastView]; TPWeakSelf; [[[TPSDNControllerClient currentInstance].quickSetupComponent requestControllerInfo] addCompletionOnMainThread:^(TPHandleResult *result) { TPStrongSelf; [_self dismissToastViewWithCompleteBlock:^{ if (result.success) { DMSDNQuickSetupInfo *quickSetupInfo = [TPSDNControllerClient currentInstance].quickSetupComponent.quickSetupInfo; _self.nameGroupView.text = quickSetupInfo.controllerName; if (IsEmptyString(quickSetupInfo.country)) { _self.selectedCountryKey = @""; _self.selectedCountryName = @""; [_self.countryGroupView updateSelectedValueWithText: gSDNGlobal.pleaseSelect]; [_self.countryGroupView updateValueWithSelectedState:NO]; _self.selectedTimezoneName = @""; [_self.timezoneGroupView updateSelectedValueWithText: gSDNGlobal.pleaseSelect]; [_self.timezoneGroupView updateValueWithSelectedState:NO]; } else { _self.selectedCountryKey = quickSetupInfo.country; if (self.coordinator.ecDevice.isCloudBasedController) { _self.selectedCountryName = [[TPSDNCountryInfoTool shareInstanceQSForEs].countryKeyDictionary objectForKey:_self.selectedCountryKey]; } else { _self.selectedCountryName = [[TPSDNCountryInfoTool shareInstance].countryKeyDictionary objectForKey:_self.selectedCountryKey]; } [_self.countryGroupView updateSelectedValueWithText:_self.selectedCountryName]; [_self.countryGroupView updateValueWithSelectedState:YES]; _self.selectedTimeZoneItem = [[TPSDNTimeZoneInfoTool shareInstance].timezoneKeyDictionary objectForKey:quickSetupInfo.timeZone]; _self.selectedTimezoneName = _self.selectedTimeZoneItem.localName; [_self.timezoneGroupView updateSelectedValueWithText:_self.selectedTimezoneName]; [_self.timezoneGroupView updateValueWithSelectedState:YES]; } [_self updateNextButtonStatus]; } }]; }]; } else { self.nameGroupView.text = quickSetupInfo.controllerName; if (IsEmptyString(quickSetupInfo.country)) { self.selectedCountryKey = @""; self.selectedCountryName = @""; [self.countryGroupView updateSelectedValueWithText: gSDNGlobal.pleaseSelect]; [self.countryGroupView updateValueWithSelectedState:NO]; } else { self.selectedCountryKey = quickSetupInfo.country; if (self.coordinator.ecDevice.isCloudBasedController) { self.selectedCountryName = [[TPSDNCountryInfoTool shareInstanceQSForEs].countryKeyDictionary objectForKey:self.selectedCountryKey]; } else { self.selectedCountryName = [[TPSDNCountryInfoTool shareInstance].countryKeyDictionary objectForKey:self.selectedCountryKey]; } if (IsEmptyString(self.selectedCountryName)) { self.selectedCountryKey = @""; self.selectedCountryName = @""; [self.countryGroupView updateSelectedValueWithText: gSDNGlobal.pleaseSelect]; [self.countryGroupView updateValueWithSelectedState:NO]; } else { [self.countryGroupView updateSelectedValueWithText:self.selectedCountryName]; [self.countryGroupView updateValueWithSelectedState:YES]; } } if (IsEmptyString(quickSetupInfo.timeZone)) { self.selectedTimezoneName = @""; [self.timezoneGroupView updateSelectedValueWithText: gSDNGlobal.pleaseSelect]; [self.timezoneGroupView updateValueWithSelectedState:NO]; } else { self.selectedTimeZoneItem = [[TPSDNTimeZoneInfoTool shareInstance].timezoneKeyDictionary objectForKey:quickSetupInfo.timeZone]; if (self.selectedTimeZoneItem == nil) { self.selectedTimezoneName = @""; [self.timezoneGroupView updateSelectedValueWithText: gSDNGlobal.pleaseSelect]; [self.timezoneGroupView updateValueWithSelectedState:NO]; } else { self.selectedTimezoneName = self.selectedTimeZoneItem.localName; [self.timezoneGroupView updateSelectedValueWithText:self.selectedTimezoneName]; [self.timezoneGroupView updateValueWithSelectedState:YES]; } } [self updateNextButtonStatus]; } } // 仅首次显示的候,才进行焦点处理。 - (void)firstViewDidAppear:(BOOL)animated { [super firstViewDidAppear:animated]; [self.nameGroupView focusOn]; } -(void)updateAgreePrivacyPolicyButtonImage { if (self.isAgreePrivacyPolicyOn) { [self.agreePrivacyPolicyButton setImage: [UIImage imageNamed: @"SDNSquareSelect"] forState:UIControlStateNormal]; } else { [self.agreePrivacyPolicyButton setImage: [UIImage imageNamed: @"SDNSquareUnselect"] forState:UIControlStateNormal]; } } -(void)updateAgreeUeipButtonImage { if (self.isAgreeUeipOn) { [self.agreeUeipButton setImage: [UIImage imageNamed: @"SDNSquareSelect"] forState:UIControlStateNormal]; } else { [self.agreeUeipButton setImage: [UIImage imageNamed: @"SDNSquareUnselect"] forState:UIControlStateNormal]; } } -(void)updateNextButtonStatus { BOOL isAgreePrivacyPolicyOn = YES; // 默认是同意的。 if (self.isSupportedAgreePrivacyPolicy) { // 在支持的情况下,则读取其具体的值。 isAgreePrivacyPolicyOn = self.isAgreePrivacyPolicyOn; } if ( !IsEmptyString(self.nameGroupView.text) && [self checkQuickSetupSDNControllerName:self.nameGroupView.text] && self.countryGroupView.isSelectedItem && self.timezoneGroupView.isSelectedItem && isAgreePrivacyPolicyOn) { [self.nextButton setEnabled:YES]; } else { [self.nextButton setEnabled:NO]; } } -(BOOL)textFieldShouldReturn:(UITextField *)textField { [self hideKeyboard]; return YES; } - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (range.length + range.location > textField.text.length) { return NO; } NSString* newString = [textField.text stringByReplacingCharactersInRange:range withString:string]; // NSInteger stringLength = [newString dataUsingEncoding:NSUTF8StringEncoding].length; if (textField == self.nameGroupView.valueField) { if(![[TPSDNControllerClient currentInstance].systemComponent.controllerInfo isVersionLowerThanV5]) { if (newString.length > 32) { return NO; } } else { if ([newString dataUsingEncoding:NSUTF8StringEncoding].length > 32) { return NO; } } } return YES; } - (void) didTapAgreePrivacyPolicyButton { DDLogDebug(@"点击选择按钮"); self.isAgreePrivacyPolicyOn = !self.isAgreePrivacyPolicyOn; [self updateAgreePrivacyPolicyButtonImage]; [self updateNextButtonStatus]; } - (void) didTapAgreeUeipButton { DDLogDebug(@"点击选择按钮"); self.isAgreeUeipOn = !self.isAgreeUeipOn; [self updateAgreeUeipButtonImage]; [self updateNextButtonStatus]; } - (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithTransitInformation:(NSDictionary *)components { DDLogDebug(@"点击文字链接"); NSString *linkText = [components objectForKey:@"target"]; DDLogDebug(@"点击文字链接 {%@}", linkText); NSString *termsStr = [TPBA11yHelper transToNOBreakStr:gAccount.accountTermsOfUse]; NSString *policyStr = [TPBA11yHelper transToNOBreakStr:gSDNQuickSetup.agreePrivacyPolicyLinkText]; if ([linkText isEqualToString:policyStr]) { [self gotoPrivacyPolicyPage]; } else if ([linkText isEqualToString:termsStr]) { [self gotoTermOfUsePage]; } else if ([linkText isEqualToString:gSDNQuickSetup.agreeUeipLinkText]) { [self gotoUEIPPage]; } } - (void)didTapNextButton { [self hideKeyboard]; [self gotoNextPage]; } // MARK: - 读取收集的数据 - (NSString *)countrollerName { return self.nameGroupView.text; } // MARK: - 页面切换 - (void)gotoSelectCountryPage { [self hideKeyboard]; NSArray *countryNameList = [NSArray new]; if (self.coordinator.ecDevice.isCloudBasedController) { countryNameList = [TPSDNCountryInfoTool shareInstanceQSForEs].countryNameDictionary.allKeys; } else { countryNameList = [TPSDNCountryInfoTool shareInstance].countryNameDictionary.allKeys; } SDNQSSelectCountryTableViewController *vc = [[SDNQSSelectCountryTableViewController alloc] initWithTitle:gSDNGlobal.countryOrRegion totalItems:countryNameList selectedItem:self.selectedCountryName]; vc.delegate = self; vc.tag = 101; UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:vc]; [self.tpNavigationController presentViewController:navVC animated:YES completion:nil]; } - (void)gotoSelectTimezonePage { [self hideKeyboard]; NSArray *timezoneNameList = [TPSDNTimeZoneInfoTool shareInstance].timeZoneNameList; SDNQSSelectTimeZoneTableViewController *vc = [[SDNQSSelectTimeZoneTableViewController alloc] initWithTitle:gSDNGlobal.timezone totalItems:timezoneNameList selectedItem:self.selectedTimezoneName autoSort:NO]; vc.delegate = self; vc.tag = 102; UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:vc]; [self.tpNavigationController presentViewController:navVC animated:YES completion:nil]; } -(void)gotoPrivacyPolicyPage { PrivacyPolicyViewController *viewController = [[PrivacyPolicyViewController alloc] init]; TPNavigationController *navVC = [[TPNavigationController alloc] initWithRootViewController:viewController]; [self.tpNavigationController presentViewController:navVC animated:YES completion:^{ }]; } -(void)gotoTermOfUsePage { TermsOfServiceViewController *viewController = [[TermsOfServiceViewController alloc] init]; TPNavigationController *navVC = [[TPNavigationController alloc] initWithRootViewController:viewController]; [self.tpNavigationController presentViewController:navVC animated:YES completion:^{ }]; } -(void)gotoUEIPPage { UserExperienceImprovementProgramViewController *viewController = [[UserExperienceImprovementProgramViewController alloc] init]; TPNavigationController *navVC = [[TPNavigationController alloc] initWithRootViewController:viewController]; [self.tpNavigationController presentViewController:navVC animated:YES completion:^{ }]; } // MARK: delegate - (void)didCompleteViewControllerWithTag:(NSInteger)vcTag andSelecteItem:(NSString *)selectedItem { if (vcTag == 101) { DDLogDebug(@"选择国家地区完毕,选择了名称为:[%@]", selectedItem); if (!IsEmptyString(selectedItem)) { self.selectedCountryName = selectedItem; if (self.coordinator.ecDevice.isCloudBasedController) { self.selectedCountryKey = [[TPSDNCountryInfoTool shareInstanceQSForEs].countryNameDictionary objectForKey:selectedItem]; } else { self.selectedCountryKey = [[TPSDNCountryInfoTool shareInstance].countryNameDictionary objectForKey:selectedItem]; } DDLogDebug(@"本地名称为:[%@]", self.selectedCountryName); DDLogDebug(@"标识码为:[%@]", self.selectedCountryKey); [self.countryGroupView updateSelectedValueWithText:selectedItem]; [self.countryGroupView updateValueWithSelectedState:YES]; } [self updateNextButtonStatus]; } else if(vcTag == 102) { DDLogDebug(@"选择区完毕,选择了:[%@]", selectedItem); if (!IsEmptyString(selectedItem)) { self.selectedTimezoneName = selectedItem; self.selectedTimeZoneItem = [[TPSDNTimeZoneInfoTool shareInstance].timezoneNameDictionary objectForKey:selectedItem]; [self.timezoneGroupView updateSelectedValueWithText:selectedItem]; [self.timezoneGroupView updateValueWithSelectedState:YES]; } [self updateNextButtonStatus]; } } @end
最新发布
12-10
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值