[英]iOS swift4, Click multiple UITextFields,Keyboard show, the UIButton that has moved up does not know why it moved down
[英]Add multiple UITextFields on UIButton click
我有一個令人困惑的問題。 我有定義為公司詳細信息的視圖,其中包含5個UITextFields
,而UITextFields
是:地址,城市,郵政編碼等。現在,有一個UIButton
用於添加一個以上的地址,該視圖添加了相同的視圖,但需要用不同的數據。 我對此沒有解決方案,這幾乎就是我所做的:
self.officeLocationsLabel = [[UILabel alloc]initWithFrame:CGRectMake(LEFT_MARGIN, self.viewForCompanyProfileImage.frame.origin.y+self.viewForCompanyProfileImage.frame.size.height+SPACE_MARGIN*2, SCREEN_WIDTH-LEFT_MARGIN*2, 40)];
self.officeLocationsLabel.text = AMLocalizedString(@"officeLocations_text", nil);
[self.officeLocationsLabel setTextColor:[UIColor blackColor]];
[self.officeLocationsLabel setFont:[UIFont systemFontOfSize:20]];
[self.mainScroll addSubview:self.officeLocationsLabel];
self.streetAddressTextField = [self createTextFieldWithFrame:CGRectMake(LEFT_MARGIN, self.officeLocationsLabel.frame.origin.y+self.officeLocationsLabel.frame.size.height+SPACE_MARGIN, SCREEN_WIDTH-LEFT_MARGIN*2, 40) andPlaceholder:AMLocalizedString(@"streetAddress_text", nil)];
[self.mainScroll addSubview:self.streetAddressTextField];
self.streetAddressLine = [self createLineUsingOrigins:self.streetAddressTextField];
[self.mainScroll addSubview:self.streetAddressLine];
self.additionalAddresInfoTextField = [self createTextFieldWithFrame:CGRectMake(LEFT_MARGIN, self.streetAddressLine.frame.origin.y+self.streetAddressLine.frame.size.height+SPACE_MARGIN, SCREEN_WIDTH-LEFT_MARGIN*2, 40) andPlaceholder:AMLocalizedString(@"additionalAddress_text", nil)];
[self.mainScroll addSubview:self.additionalAddresInfoTextField];
self.additionalAddressLine = [self createLineUsingOrigins:self.additionalAddresInfoTextField];
[self.mainScroll addSubview:self.additionalAddressLine];
self.countryTextField = [self createTextFieldWithFrame:CGRectMake(LEFT_MARGIN, self.additionalAddressLine.frame.origin.y+self.additionalAddressLine.frame.size.height+SPACE_MARGIN, SCREEN_WIDTH/3, 40) andPlaceholder:AMLocalizedString(@"countryName_text", nil)];
[self.mainScroll addSubview:self.countryTextField];
self.countryLine = [self createLineUsingOrigins:self.countryTextField];
[self.mainScroll addSubview:self.countryLine];
self.zipCodeTextField = [self createTextFieldWithFrame:CGRectMake(self.countryTextField.frame.origin.x+self.countryTextField.frame.size.width+LEFT_MARGIN, self.additionalAddressLine.frame.origin.y+self.additionalAddressLine.frame.size.height+SPACE_MARGIN, SCREEN_WIDTH-SCREEN_WIDTH/3-LEFT_MARGIN*3, 40) andPlaceholder:AMLocalizedString(@"zipCode_text", nil)];
[self.mainScroll addSubview:self.zipCodeTextField];
self.zipCodeLine = [self createLineUsingOrigins:self.zipCodeTextField];
[self.mainScroll addSubview:self.zipCodeLine];
self.addOfficeLocation = [[UIButton alloc]initWithFrame:CGRectMake(LEFT_MARGIN, self.zipCodeLine.frame.origin.y+self.zipCodeLine.frame.size.height+SPACE_MARGIN, SCREEN_WIDTH/2, 40)];
[self.addOfficeLocation setTitle:AMLocalizedString(@"addOfficeLocation_text", nil) forState:UIControlStateNormal];
[self.addOfficeLocation setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
self.addOfficeLocation.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
[self.mainScroll addSubview:self.addOfficeLocation];
您的問題可能有很多解決方案:
scrollView
於scrollView
都將顯示出來,並通過單擊按鈕顯示它們(不要忘記增加scrollView
的內容大小) 。 雖然這不是整齊的 。 tableView
。 而且,每當您單擊按鈕時,都會用新部分重新加載表格。 讓我知道您是否需要更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.