【发布时间】:2015-10-26 09:24:33
【问题描述】:
我有一个相当混乱的问题。我有定义为公司详细信息的视图,其中包含 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];
【问题讨论】:
-
你的问题是什么?您想在按下按钮时添加所有 5 个文本字段吗?
-
是的,我想添加相同的 5 个文本字段,并输入与前五个不同的数据,并将它们保存在数组中。就像同一家公司的不同地点一样。
标签: ios objective-c uibutton uitextfield