在我的應用程序中,我在tableview上有37個textfield進行滾動。如果假設我在第一個文本框中輸入了一些值並滾動了表格,那麼在第一個文本文件中輸入的值以及layout可以幫助我輸入值。如何在滾動時設置textfield內容?
下面是我的代碼:
#import "Edit.h"
@implementation Edit
@synthesize tableContents,textField,scrollView;
@synthesize txtUserName,txtFirstName,txtLastName,txtNickName,txtDisplayName,txtEmail,txtWebSite,txtAboutMe,txtNewPassword,txtPasswordAgain;
@synthesize txtPayPalEmail ,txtActiveMemPk ,txtMemPkExpireDate;
@synthesize txtBusinessName ,txtAbnAcn ,txtContactName ,txtPhone ,txtFax ,txtMobile ,txtBusinessEmail ,txtFacebookLink ,txtLinkedinLink ,txtMySpaceLink;
@synthesize txtBlogLink ,txtInstanMessage ,txtWebsite ,txtStreet ,txtCitySuburb ,txtZipCode ,txtState ,txtTradingHour;
@synthesize txtActiveOfService ,txtTradeOnWeekend ,txtProduct , txtService ,txtPickUpAndDelivery;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
//self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"main-bg.png"]];
UIBarButtonItem *updatebtn = [[UIBarButtonItem alloc]
initWithTitle:@"Update"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(update)];
self.navigationItem.rightBarButtonItem = updatebtn;
[updatebtn release];
[super viewDidLoad];
NSArray *text = [[NSArray alloc]initWithObjects:@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",@"",nil];
NSDictionary *textData = [[NSDictionary alloc]initWithObjectsAndKeys:text,@"",nil];
self.tableContents = textData;
self.textField = [[self.tableContents allKeys] sortedArrayUsingSelector:@selector(compare:)];
}
-(NSInteger) numberOfSectionInTableView:(UITableView *)tableView
{
return[self.textField count];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSArray *lsData =[self.tableContents objectForKey:[self.textField objectAtIndex:section]];
return [lsData count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *TextCellIdentifier [email protected]"Cell";
UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:TextCellIdentifier];
if (cell==nil)
{
cell=[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TextCellIdentifier ] autorelease];
cell.accessoryType= UITableViewCellAccessoryNone;
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.font = [UIFont fontWithName:@"Helvetica" size:14];
}
if ([indexPath row]==0)
{
txtUserName=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
[email protected]"username";
txtUserName.autocorrectionType=UITextAutocorrectionTypeNo;
[txtUserName setClearButtonMode:UITextFieldViewModeWhileEditing];
[txtUserName setEnabled:YES];
cell.accessoryView=txtUserName;
[email protected]"User Name:";
}
if ([indexPath row]==1)
{
txtFirstName=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
[email protected]"first name";
cell.accessoryView=txtFirstName;
[email protected]"First Name:";
}
if ([indexPath row]==2)
{
txtLastName=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
[email protected]"last name";
cell.accessoryView=txtLastName;
[email protected]"Last Name";
}
if ([indexPath row]==3)
{
txtNickName=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
[email protected]"nick name";
cell.accessoryView=txtNickName;
[email protected]"Nick Name";
}
if ([indexPath row]==4)
{
txtDisplayName=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
[email protected]"display name";
cell.accessoryView=txtDisplayName;
[email protected]"Diaplay Name:";
}
if ([indexPath row]==5)
{
txtEmail=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
[email protected]"email";
cell.accessoryView=txtEmail;
[email protected]"Email ID:";
//txtEmail.text=[NSString stringWithFormat:@"%@",user_email];
//cell.textAlignment=UITextAlignmentRight;
}
if ([indexPath row]==6)
{
txtWebSite=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
[email protected]"website";
cell.accessoryView=txtWebSite;
[email protected]"Website:";
}
if ([indexPath row]==7)
{
txtAboutMe=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
cell.accessoryView=txtAboutMe;
[email protected]"About Me:";
//cell.font =[UIFont fontWithName:@"impact" size:14];
//txtAboutMe.font=[UIFont boldSystemFontOfSize:20];
//txtAboutMe.backgroundColor=[UIColor clearColor];
//cell.textAlignment=UITextAlignmentRight;
}
if ([indexPath row]==8)
{
txtNewPassword=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
[email protected]"new password";
cell.accessoryView=txtNewPassword;
[email protected]"New Password:";
}
if ([indexPath row]==9)
{
txtPasswordAgain=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
[email protected]"confirm password";
cell.accessoryView=txtPasswordAgain;
[email protected]"Confirm Password:";
}
if ([indexPath row]==10)
{
UILabel *lblExtendedProfileInfo=[[UILabel alloc] initWithFrame:CGRectMake(0,0,270,25)];
[email protected]"Extended Profile Information:";
lblExtendedProfileInfo.font=[UIFont boldSystemFontOfSize:14];
cell.accessoryView=lblExtendedProfileInfo;
lblExtendedProfileInfo.textAlignment=UITextAlignmentLeft;
}
if ([indexPath row]==11)
{
txtPayPalEmail=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
[email protected]"pay pal email";
cell.accessoryView=txtPayPalEmail;
[email protected]"Pay Pal Email";
}
if ([indexPath row]==12)
{
txtActiveMemPk=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
[email protected]"Active Member Pack";
cell.accessoryView=txtActiveMemPk;
[email protected]"Active Memberhip:";
}
if ([indexPath row]==13)
{
txtMemPkExpireDate=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
[email protected]"member pack expire date";
cell.accessoryView=txtMemPkExpireDate;
[email protected]"Membership Pack:";
}
if ([indexPath row]==14)
{
UILabel *lblExtendedProfileInfo=[[UILabel alloc] initWithFrame:CGRectMake(0,0,270,25)];
[email protected]"Business Information:";
lblExtendedProfileInfo.font=[UIFont boldSystemFontOfSize:14];
cell.accessoryView=lblExtendedProfileInfo;
//lblExtendedProfileInfo.textAlignment=UITextAlignmentLeft;
}
if ([indexPath row]==15)
{
txtBusinessName=[[UITextField alloc]initWithFrame:CGRectMake(0, 0, 150, 25)];
[email protected]"Business name";
cell.accessoryView=txtBusinessName;
[email protected]"Business Name:";
}
if ([indexPath row]==16)
{
txtAbnAcn=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]" Abn /Acn";
cell.accessoryView=txtAbnAcn;
[email protected]"Abn/Acn:";
}
else if ([indexPath row]==17)
{
txtContactName=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Contact Name";
cell.accessoryView=txtContactName;
[email protected]"Contact Name:";
}
else if ([indexPath row]==18)
{
txtPhone=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Phone No";
cell.accessoryView=txtPhone;
[email protected]"Phone No:";
}
else if ([indexPath row]==19)
{
txtFax=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Fax ";
cell.accessoryView=txtFax;
[email protected]"Fax:";
}
else if ([indexPath row]==20)
{
txtMobile=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Mobile No";
cell.accessoryView=txtMobile;
[email protected]"Mobile No:";
}
else if ([indexPath row]==21)
{
txtBusinessEmail=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]" Business Email";
cell.accessoryView=txtBusinessEmail;
[email protected]"Business Email:";
}
else if ([indexPath row]==22)
{
txtFacebookLink=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Facebook Link";
cell.accessoryView=txtFacebookLink;
[email protected]"Facebook Link:";
}
else if ([indexPath row]==23)
{
txtLinkedinLink=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Linked In Link";
cell.accessoryView=txtLinkedinLink;
[email protected]"Linked In Link:";
}
else if ([indexPath row]==24)
{
txtMySpaceLink=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"My Space Link";
cell.accessoryView=txtMySpaceLink;
[email protected]"My Space Link:";
}
else if ([indexPath row]==25)
{
txtBlogLink=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Blog Link";
cell.accessoryView=txtBlogLink;
[email protected]"Blog Link:";
}
else if ([indexPath row]==26)
{
txtInstanMessage=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Instant Message";
cell.accessoryView=txtInstanMessage;
[email protected]"Instant Message:";
}
else if ([indexPath row]==27)
{
txtWebsite=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Web Site";
cell.accessoryView=txtWebsite;
[email protected]"Web Site:";
}
else if ([indexPath row]==28)
{
txtStreet=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Street";
cell.accessoryView=txtStreet;
[email protected]"Street:";
}
else if ([indexPath row]==29)
{
txtCitySuburb=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"City Suburb";
cell.accessoryView=txtCitySuburb;
[email protected]"City Suburb:";
}
else if ([indexPath row]==30)
{
txtZipCode=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Zip Code";
cell.accessoryView=txtZipCode;
[email protected]"Zip Code:";
}
else if ([indexPath row]==31)
{
[email protected]"State:";
cell.textAlignment=UITextAlignmentRight;
//arrayData = [[NSArray alloc] initWithArray:[NSArray arrayWithObjects:@"Vinod",@"Parth",@"Nilesh",nil]];
//
// stateDropDownBox = [[DropDownView alloc] initWithArrayData:arrayData cellHeight:30 heightTableView:100 paddingTop:-8 paddingLeft:-5 paddingRight:-10 refView:stateDDownBox animation:BLENDIN openAnimationDuration:2 closeAnimationDuration:2];
//
// stateDropDownBox.delegate = self;
// [self.view addSubview:stateDropDownBox.view];
//
// stateDDownBox=[UIButton buttonWithType:UIButtonTypeCustom];
// //ddState.frame=CGRectMake(0, 0,360,45);
// stateDDownBox.frame=CGRectMake(0, 0,320,45);
// UIImage *img=[UIImage imageNamed:@"drop-down-box.png"];
// [stateDDownBox setBackgroundImage:img forState:UIControlStateNormal];
// [stateDDownBox addTarget:self action:@selector(dropDownClick) forControlEvents:UIControlEventTouchUpInside];
// [stateDDownBox setTitle:[arrayData objectAtIndex:0] forState:UIControlStateNormal];
// cell.accessoryView=stateDDownBox;
}
else if ([indexPath row]==32)
{
txtTradingHour=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Trading Hour";
cell.accessoryView=txtTradingHour;
[email protected]"Trading Hour:";
}
if ([indexPath row]==33)
{
txtActiveOfService=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Active Of Service";
cell.accessoryView=txtActiveOfService;
[email protected]"Active Of Service:";
}
else if ([indexPath row]==34)
{
txtTradeOnWeekend=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Trade Of Weekend";
cell.accessoryView=txtTradeOnWeekend;
[email protected]"Do you trade on Weekends?:";
// button=[UIButton buttonWithType:UIButtonTypeCustom];
// button.frame=CGRectMake(0, 0,360,45);
// UIImage *img=[UIImage imageNamed:@"button_back.png"];
// [button setBackgroundImage:img forState:UIControlStateNormal];
// [button addTarget:self action:@selector(actionButtonClick) forControlEvents:UIControlEventTouchUpInside];
// [button setTitle:[arrayData objectAtIndex:0] forState:UIControlStateNormal];
// cell.accessoryView=button;
}
else if ([indexPath row]==35)
{
txtProduct=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Product";
cell.accessoryView=txtProduct;
[email protected]"Product:";
//txtProduct.text=[NSString stringWithFormat:@"%@",business_product];
//cell.textAlignment=UITextAlignmentRight;
}
else if ([indexPath row]==36)
{
txtPickUpAndDelivery=[[UITextField alloc] initWithFrame:CGRectMake(0,0,150,25)];
[email protected]"Pickup and Delivery";
cell.accessoryView=txtPickUpAndDelivery;
[email protected]"Pickup and Delivery:";
//txtPickUpAndDelivery.text=[NSString stringWithFormat:@"%@",business_delivery];
//cell.textAlignment=UITextAlignmentRight;
}
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
//-(BOOL)textFieldShouldReturn:(UITextField *)textField {
// [textField resignFirstResponder];
// return YES;
//}
@end
可以PLZ建議...如何設置一個文本框35 uivew –
以UIScrollView並使用interfacebuilder添加所需的文本區域。使用界面構建器將加速您的任務。看到我更新的答案。 –
rahul先生我不能添加textfiled下面的看法...... –