我很难找出在键盘弹出时让我的uitextfields不被隐藏的最佳方法。现在我有一个包含uitableview子视图和按钮的UIView。
* uiview内部的tableview实际上是一个带有编程创建的tableivew的uiviewcontroller,所以它不受uitableviewcontroller的控制。
我已经完成了研究,我想我需要一个滚动视图,然后将视图添加到滚动视图,并在选择特定文本字段时进行一些滚动,并通过键盘向上滚动来隐藏。
这是一个好方法吗?
更新:
我有两个独立的Viewcontrollers。例如,让我们说MainViewcontroller和SecondViewcontroller。 secondviewcontroller中有一个uitableview。 tableview内部的单元格具有存储用户信息的文本框(如表单)。然后我做了什么是在mainviewcontroller内创建了secondviewcontroller的对象。我做到了这一点,因为我需要在视图的底部有一个“下一个按钮”。当我选择一个字段时,它会位于键盘下方,当它弹出时我希望它向上滚动,当关闭时它会下降。我不得不使用uitableview的对象,因为Mainviewcontroller类会变大。(如果我错了请纠正我)。谢谢回复。
以下是我想要做的截图... FUll UIView:http://postimage.org/image/puzdwpj3t/ 键盘打开时:http://postimage.org/image/g5nkwzwpd/
//这是一些代码: 这里的第一个类是例如SecondViewcontroller。 2.第二部分代码例如是mainviewcontroller,它创建了一个secondviewcontroller对象。
下面的uiviewcontroller将创建一个包含3个部分的表。每个单元格都有一个文本字段(中间除外,它是一个拉出uipickerview的按钮)。这不是一个完整的类我只采取了创建表的区域。
-(void)viewDidLoad{
[super viewDidLoad];
// scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 300, 500)];
// scrollview.pagingEnabled = YES;
//
// //[scrollview addSubview:self.view];
// [self.view addSubview:scrollview];
table.scrollEnabled = YES;
dataArray = [[NSMutableArray alloc] init];
titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 290, 30)];
//dropper
titleField = [[UITextField alloc] initWithFrame:CGRectMake(10, 2, 300, 30)];
titleField.layer.cornerRadius = 8;
titleField.backgroundColor = [UIColor clearColor];
NSArray *firstItemsArray = [[NSArray alloc] initWithObjects:@"1",@"2", nil];
NSDictionary *firstItemsArrayDict = [NSDictionary dictionaryWithObject:firstItemsArray forKey:@"data"];
[dataArray addObject:firstItemsArrayDict];
//Second section dat
NSArray *secondItemsArray = [[NSArray alloc] initWithObjects:@"1", nil];
NSDictionary *secondItemsArrayDict = [NSDictionary dictionaryWithObject:secondItemsArray forKey:@"data"];
[dataArray addObject:secondItemsArrayDict];
NSArray *thirdItemsArray = [[NSArray alloc] initWithObjects:@"1",@"2",@"3", nil];
NSDictionary *thirdItemsArrayDict = [NSDictionary dictionaryWithObject:thirdItemsArray forKey:@"data"];
[dataArray addObject:thirdItemsArrayDict];
NSLog(@"the dataArray%@",dataArray);
if([self connectedToNetwork]){
dispatch_async(kBgQueue, ^{
//build the url of strings
FULLURL = [SERVERNAME stringByAppendingFormat:TitleLink];
//create the url
NSURL *url = [[NSURL alloc] initWithString:FULLURL];
//NSLog(@"here title url%@",url);
//get the data from the url
NSData* data = [NSData dataWithContentsOfURL: url];
//NSLog(@"here%@",data);
//get the data from the url
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
// NSLog(@"titleid:%@",TITLEID);
// NSLog(@"title categories:%@",titlecategories);
});
[table setBounces:NO];
}else{
dispatch_async(dispatch_get_main_queue(), ^ {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Please Check your internet connection"
message:@"Enable your internet connection"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
});
}
}
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return [dataArray count];
}
-(NSInteger) tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
//Number of rows it should expect should be based on the section
NSDictionary *dictionary = [dataArray objectAtIndex:section];
NSArray *array = [dictionary objectForKey:@"data"];
return [array count];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 1){
cell.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:@"longdropper300.png"]];
}
else{
cell.backgroundColor = [UIColor whiteColor];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
textField = [[UITextField alloc] initWithFrame:CGRectMake(15, 10, 290, 30)];
static NSString *cellValue = @"Cell";
UITableViewCell *cell =nil;
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellValue];
}
cell.selectionStyle = UITableViewCellSelectionStyleGray;
if ([indexPath section] == 0) {
//cellValue=[items objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryNone;
cell.selectionStyle= UITableViewCellSelectionStyleNone;
//textField.tag = 1;
textField.adjustsFontSizeToFitWidth = YES;
textField.textColor = [UIColor blackColor];
if(indexPath.section == 0){
//textfield for email
if ([indexPath row] == 0) {
textField.tag = 1;
textField.text = EMAIL;
textField.textColor= [UIColor blackColor];
textField.placeholder = @"Email: example@gmail.com";
textField.keyboardType = UIKeyboardTypeEmailAddress;
textField.returnKeyType = UIReturnKeyNext;
}
//textfield for phone number
else {
textField.tag = 2;
if ([PHONENUMBER isEqual: [NSNull null]] && PHONENUMBER == nil && PHONENUMBER == NULL && [PHONENUMBER isEqual: @""]){
NSLog(@"phone is empty%@",PHONENUMBER);
//[PHONENUMBER isEqual:@"frank"];
}else{
NSLog(@"phone is not empty%@",PHONENUMBER);
textField.text = PHONENUMBER;
}
textField.placeholder = @"Phone: xxx-xxx-xxxx";
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.secureTextEntry = NO;
}
textField.backgroundColor = [UIColor whiteColor];
textField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
textField.textAlignment = UITextAlignmentLeft;
textField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
[textField setEnabled: YES];
textField.delegate = self;
[cell addSubview:textField];
}
}
if(indexPath.section == 1){
[titleField setTextColor:[UIColor whiteColor]];
titleField.tag = 3;
titleField.placeholder = @"Select Contact Title";
titleField.returnKeyType = UIReturnKeyNext;
//titleField == textField.tag = 3;
if ([TITLENAME isEqual: [NSNull null]]){
NSLog(@"titlename is empty%@",TITLENAME);
}else{
NSLog(@"titlename is not empty%@",TITLENAME);
titleField.text = TITLENAME;
}
titleField.keyboardType = UIKeyboardTypeDefault;
titleField.returnKeyType = UIReturnKeyDone;
titleField.secureTextEntry = NO;
titleField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
titleField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
titleField.textAlignment = UITextAlignmentCenter;
titleField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
[titleField setEnabled: NO];
titleField.delegate = self;
[cell addSubview:titleField];
NSLog(@"here is the titlename%@",TITLENAME);
}
if(indexPath.section == 2){
if ([indexPath row] == 0) {
textField.tag = 4;
textField.placeholder = @"First Name";
cell.selectionStyle= UITableViewCellSelectionStyleNone;
if ([FIRSTNAME isEqual: [NSNull null]]){
NSLog(@"firstname is empty%@",FIRSTNAME);
textField.text = @"";
}else{
textField.text = FIRSTNAME;
}
textField.keyboardType = UIKeyboardTypeEmailAddress;
textField.returnKeyType = UIReturnKeyNext;
}
if([indexPath row] == 1){
textField.tag = 5;
textField.placeholder = @"Last Name";
if ([LASTNAME isEqual: [NSNull null]]){
NSLog(@"lastname is empty%@",LASTNAME);
textField.text = @"";
}else{
textField.text = LASTNAME;
}
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyNext;
//textField.secureTextEntry = NO;
}
if([indexPath row] == 2){
textField.tag = 6;
textField.placeholder = @"Company";
if ([COMPANY isEqual: [NSNull null]]){
NSLog(@"company is empty%@",COMPANY);
textField.text = @"";
}
else{
textField.text = COMPANY;
}
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.secureTextEntry = NO;
}
//]textField.backgroundColor = [UIColor whiteColor];
textField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support
textField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
textField.textAlignment = UITextAlignmentLeft;
textField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right
[textField setEnabled: YES];
textField.delegate = self;
[cell addSubview:textField];
}
return cell;
}
//Change the Height of title cell drop down
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
if (indexPath.section == 1) {
if (indexPath.row == 0) {
return 30;
}
}
return 45;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
if(([textField tag] == 1)){
NSString *emailRegEx = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegEx];
//Valid email address
if ([emailTest evaluateWithObject:textField.text] == YES)
{
EMAIL = [textField.text copy];
NSLog(@"here is the email%@",EMAIL);
}
else
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Bad Email"
message: @"Please Re-enter the email address with a valid email"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
textField.text = nil;
NSLog(@"email not in proper format");
}
}
if(([textField tag] == 2)){
NSString *phoneRegex = @"[235689][0-9]{6}([0-9]{3})?";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", phoneRegex];
//valid email address
if ([phoneTest evaluateWithObject:textField.text] == YES)
{
PHONENUMBER = [textField.text copy];
NSLog(@"here is the phone number %@",PHONENUMBER);
}
else
{
NSLog(@"Phone Number Invalid");
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"xxx-xxx-xxxx"
message: @"Please enter a valid phone number"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
textField.text = nil;
}
}
if(([textField tag] == 4)){
FIRSTNAME = [textField.text copy];
NSLog(@"here is the firstName%@",FIRSTNAME);
}
if(([textField tag] == 5)){
LASTNAME = [textField.text copy];
NSLog(@"here is the Last Name%@",LASTNAME);
}
if(([textField tag] == 6)){
COMPANY = [textField.text copy];
NSLog(@"here is the Company%@",COMPANY);
}
return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField*)textField;
{
NSInteger nextTag = textField.tag + 1;
// Try to find next responder
UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
if (nextResponder) {
// Found next responder, so set it.
[nextResponder becomeFirstResponder];
} else {
// Not found, so remove keyboard.
[textField resignFirstResponder];
}
return NO; // We do not want UITextField to insert line-breaks.
}
主视图控制器 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if(self){ //自定义初始化 } 回归自我; }
- (void)addMyButton{ // Method for creating button, with background image and other properties
loginButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
loginButton.frame = CGRectMake(10.0,130.0, 300.0, 40.0);
[loginButton setTitle:@"Login" forState:UIControlStateNormal];
loginButton.backgroundColor = [UIColor clearColor];
[loginButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal ];
UIImage *buttonImageNormal = [UIImage imageNamed:@"blueButton.png"];
UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[loginButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];
UIImage *buttonImagePressed = [UIImage imageNamed:@"whiteButton.png"];
UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
[loginButton setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];
[self.view addSubview:loginButton];
[loginButton addTarget: self
action: @selector(loginButtonClicked:)
forControlEvents: UIControlEventTouchUpInside];
}
//Change the View and send the information to the servlet once login is clicked.
- (void)loginButtonClicked: (id)sender{
loginButton.enabled = NO;
activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(20, 60, 20, 20)];
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityIndicator];
[self navigationItem].rightBarButtonItem = barButton;
[activityIndicator startAnimating];
[passwordTF resignFirstResponder];
//start new thread
//dispatch_async(kBgQueue, ^{
NSLog(@"Username:%@",USERNAME);
NSLog(@"Password:%@",PASSWORD);
NSLog(@"COMPANYID: %@", COMPANYID);
//NSLog(@"LOGINID: %@", LOGINID);
if((USERNAME == NULL) || (USERNAME == nil) || ([USERNAME isEqualToString:@""])){
//NSLog(@"null password or usernaem");
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Username or password not found"
message:@"please try again"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[activityIndicator stopAnimating];
// MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
// [self.navigationController pushViewController:SenderInfoViews animated:NO];
}else if((PASSWORD == NULL) || (PASSWORD == nil) || ([PASSWORD isEqualToString:@""])){
//NSLog(@"null password or usernaem");
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Username or password not found"
message:@"please try again"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[activityIndicator stopAnimating];
// MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
// [self.navigationController pushViewController:SenderInfoViews animated:NO];
}else{
//NSLog(@"all good");
NSLog(@"Login button clicked, load the next view and check for password");
NSLog(@"full the url%@",FULLURL);
//build the url of strings
FULLURL = ******
if([self connectedToNetwork])
{
dispatch_queue_t downloadQueue = dispatch_queue_create("data loader", NULL);
dispatch_async(downloadQueue, ^{
//create the url
NSURL *url = [[NSURL alloc] initWithString:FULLURL];
NSLog(@"here%@",url);
//get the data from the url
NSData* data = [NSData dataWithContentsOfURL: url];
NSLog(@"here%@",data);
NSLog(@"here that data%@",data);
if(data != nil){
//
//get the data from the url
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
//
NSLog(@"hello Username:%@",USERNAME);
NSLog(@"Password:%@",PASSWORD);
NSLog(@"h4llo COMPANYID: %@", COMPANYID);
NSLog(@"LOGINID: %@", LOGINID);
//
// // [self performSelectorOnMainThread:@selector(checkLogin:) withObject:LOGINID waitUntilDone:YES];
//
//
@try {
//NSLog(@"before loginddd %@",LOGINID);
if(COMPANYID != 0){
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:USERNAME forKey:@"UserName"];
[prefs setObject:@"Pass" forKey:@"Pass"];
// This is suggested to synch prefs, but is not needed
[prefs synchronize];
NSLog(@"here is the login identiy%@",LOGINID);
MangoContactSelection *SenderInfoViews = [[MangoContactSelection alloc] init];
[self.navigationController pushViewController:SenderInfoViews animated:NO];
}
else{
dispatch_async(dispatch_get_main_queue(), ^ {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"bad NAME"
message:@"GOO"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
// [self.view setNeedsDisplay];
[self.view reloadInputViews];
MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
[self.navigationController pushViewController:SenderInfoViews animated:NO];
[activityIndicator stopAnimating];
});
}
}
@catch (NSException * e) {
NSLog(@"Exception: %@", e);
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Login Failed"
message:@"Bad"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
//[activityIndicator stopAnimating];
}
// if the data is nil do this
}else{
dispatch_async(dispatch_get_main_queue(), ^ {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"No Internet!"
message:@"Please Check your internet Connection"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[self.view setNeedsDisplay];
MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
[self.navigationController pushViewController:SenderInfoViews animated:NO];
});
}
dispatch_async(dispatch_get_main_queue(), ^ {
//UIImage *image = [UIImage imageWithData:imageData];
//[table reloadData];
//[actIndicator stopAnimating];
[self.view reloadInputViews];
[activityIndicator stopAnimating];
// sender because that's the element that called us by clicking refresh
});
});
}else{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"No Internet!"
message:@"Please Check your internet Connection"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
[self.view setNeedsDisplay];
MangoLoginViewController *SenderInfoViews = [[MangoLoginViewController alloc] init];
[self.navigationController pushViewController:SenderInfoViews animated:NO];
}
}
[self.view reloadInputViews];
}//login
-(void)gobacktoContactCreate{
MangoContactSelection *gobackhome = [[MangoContactSelection alloc]init];
[self.navigationController pushViewController:gobackhome animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
//self.view setBackgroundColor:([UIColor blackColor]);
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *userName = [prefs stringForKey:@"UserName"];
//NSString *pass = [prefs stringForKey:@"Pass"];
//navigation bar
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
[self.navigationController setNavigationBarHidden: NO animated:NO];
self.navigationItem.hidesBackButton = YES;
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:@selector(gobacktoContactCreate)];
self.navigationItem.title=@"Login";
//User name text field................
usernameTF = [[UITextField alloc] initWithFrame:CGRectMake(10, 25, 300, 40)];
usernameTF.borderStyle = UITextBorderStyleRoundedRect;
usernameTF.font = [UIFont systemFontOfSize:15];
usernameTF.placeholder = @"Username";
usernameTF.text = userName;
usernameTF.autocorrectionType = UITextAutocorrectionTypeNo;
usernameTF.keyboardType = UIKeyboardTypeDefault;
usernameTF.returnKeyType = UIReturnKeyNext;
usernameTF.clearButtonMode = UITextFieldViewModeWhileEditing;
usernameTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
//User name text field................
passwordTF = [[UITextField alloc] initWithFrame:CGRectMake(10, 75, 300, 40)];
passwordTF.borderStyle = UITextBorderStyleRoundedRect;
passwordTF.font = [UIFont systemFontOfSize:15];
passwordTF.placeholder = @"Password";
passwordTF.autocorrectionType = UITextAutocorrectionTypeNo;
passwordTF.keyboardType = UIKeyboardTypeDefault;
passwordTF.returnKeyType = UIReturnKeyDone;
passwordTF.clearButtonMode = UITextFieldViewModeWhileEditing;
passwordTF.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
passwordTF.secureTextEntry = YES;
//create the clickable labels
//register link
registerLabel = [[UILabel alloc]initWithFrame:CGRectMake(150,170, 150, 20)];
registerLabel.text = @"Request an account";
registerLabel.font = [UIFont systemFontOfSize:12];
registerLabel.userInteractionEnabled = YES;
registerLabel.textColor = [UIColor blueColor];
UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(requestRegistration:)];
[registerLabel addGestureRecognizer:gr];
gr.numberOfTapsRequired = 1;
gr.cancelsTouchesInView = NO;
//create the label for
registerText = [[UILabel alloc]initWithFrame:CGRectMake(60,170, 90, 20)];
registerText.text = @"New to *******?";
registerText.font = [UIFont systemFontOfSize:12];
// //forgot password link
// forgotPassword = [[UILabel alloc]initWithFrame:CGRectMake(210,190, 150, 20)];
// forgotPassword.font = [UIFont systemFontOfSize:12];
// forgotPassword.textColor = [UIColor blueColor];
// forgotPassword.text = @"Forgot Password?";
// forgotPassword.userInteractionEnabled = YES;
// UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(requestForgottenPassword:)];
// [registerLabel addGestureRecognizer:tapRec];
// tapRec.numberOfTapsRequired = 1;
// tapRec.cancelsTouchesInView = NO;
[self.view addSubview:passwordTF];
[self.view addSubview:usernameTF];
[self.view addSubview:registerLabel];
[self.view addSubview:registerText];
// [self.view addSubview:forgotPassword];
[self addMyButton];
usernameTF.delegate = self;
passwordTF.delegate = self;
}
-(void)requestRegistration:(UITapGestureRecognizer *)gr{
//for registration
NSLog(@"request registration link clicked");
}
-(void)requestNewPassword:(UITapGestureRecognizer *)tapRec{
//for registration
NSLog(@"request password link clicked");
}
//Grabs the Json from the servlet and then parses it for the username and password.
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
//NSLog(@"here is the login info from json: %@", json);
// NSString *FALSELOGIN;
COMPANYID = [json valueForKey:@"companyid"];
NSLog(@"COMPANY ID: %@", COMPANYID);
// LOGINID = [json valueForKey:@"login"];
// NSLog(@"LOGIN ID: %@", LOGINID);
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
if((textField = usernameTF)){
USERNAME = [textField.text copy];
//NSLog(@"here is the string for username;%@", USERNAME);
}
if((textField = passwordTF)){
PASSWORD = [textField.text copy];
//NSLog(@"here is the password guy %@",PASSWORD);
}
return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == usernameTF) {
[passwordTF becomeFirstResponder];
}
else{
[passwordTF resignFirstResponder];
}
return YES;
}
//- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
//{
// [passwordTF resignFirstResponder];
//
//}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
答案 0 :(得分:0)
您已在UIViewController的视图中添加了Tableview。正确?
您在哪个视图中添加了UITextview。 UIViewController的视图??
您可以在UIView中添加UITextView,只需更改UITextView的框架即可应用动画。
实施例。
//观看视频....
[UIView animationWithDuration:secs delay:0.0 option:option animation:^{
CGRect frame = textview.frame;
frame.origin.y = 10; // Change Y position of frame.
textview.frame = frame;
}
completion:nil];
//向下看
[UIView animationWithDuration:secs delay:0.0 option:option animation:^{
CGRect frame = textview.frame;
frame.origin.y = 100; // Change Y position of frame.
textview.frame = frame;
}
completion:nil];
无需使用UIScrollView。
答案 1 :(得分:0)
Dhaval,我相信你的解决方案会奏效,但我最终找到了我在这里寻找的东西:
http://www.youtube.com/watch?feature=player_detailpage&v=qSvDWnasJ9I
感谢。