resignFirstResponder is not working as expected - iphone

I am having the uitextfield to input country value inside the uitableview. When tapping on that field I am showing the tableview with country values loaded.
When tapping on any cell, it comes back to the same form and adds the selected value inside the country field. I mean I assign the selected value to the textfield inside the viewwillappear method. After setting the text inside the country field. I want to resign the keyboard, so I added resignFirstResponder, but it is not resigning the keyboard.
Below is my code:
- (void)textFieldDidBeginEditing:(UITextField *)textField;
{
if( textField == self.myCountryField ){
aCountryListView =
[[LCCountryListViewController alloc]init];
UINavigationController *navigationController =
[[UINavigationController alloc]
initWithRootViewController:aCountryListView];
[self presentModalViewController:navigationController animated:YES];
}
}
-(void)viewWillAppear:(BOOL)animated{
//-----------------------------------
self.myCountryField.text = aCountryListView.mySelectedCountry;
[self.myCountryField resignFirstResponder];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
//-------------------------------------------------------------------------------
{
static NSString *CellIdentifier = #"PoetNameCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.backgroundColor = [UIColor clearColor];
if( indexPath.row == 0 ){
UILabel *aLblTitle = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 220, 30)];
aLblTitle.backgroundColor = [UIColor clearColor];
aLblTitle.font = [UIFont fontWithName:#"Palatino-Bold" size:16.0];
aLblTitle.text = NSLocalizedString(#"Country","Country");
aLblTitle.textColor = [UIColor whiteColor];
[cell.contentView addSubview:aLblTitle];
myCountryField = [[UITextField alloc]initWithFrame:CGRectMake(133,5,150,30)];
myCountryField.backgroundColor = [UIColor whiteColor];
myCountryField.delegate = self;
myCountryField.borderStyle = UITextBorderStyleRoundedRect;
[cell.contentView addSubview:myCountryField];
}
return cell;
}

use the below code, hope it will help you out.
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self.view endEditing:YES];
return YES;
}
ensure that you will connect your delegate to fileowner in xib-file. or in viewDidload use the following code.
yourtextfield.delegate=self;
and in your .h file use <UITextfielddelegate>

Hope the following code will work when add UITextField delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self.myCountryField resignFirstResponder];
return YES;
}

How about using this instead:
[[UIApplication sharedApplication] sendAction:#selector(resignFirstResponder)
to:nil
from:nil
forEvent:nil];

Related

First responder is not being set in custom TableView having custom textfield

I have a table containing buttons and textfields
i am creating new cell when i click or a text field or row
But when i have more than one rows, it does not assign first responder to the textfield when i tap on textfield to directly to another field
here is my code for both cellForRowAtIndexPath and textFieldDidEndEditing
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell= [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
wholeSale = [[UITextField alloc] initWithFrame:CGRectMake(240, 0, 100, 32)];
wholeSale.borderStyle = UITextBorderStyleLine;
wholeSale.layer.borderWidth=2.0f;
wholeSale.layer.borderColor=[UIColor colorWithRed:81/255.0 green:105/255.0 blue:169/255.0 alpha:(1)].CGColor;
wholeSale.clipsToBounds=YES;
[wholeSale setFont:[UIFont boldSystemFontOfSize:14]];
[wholeSale setTextAlignment:UITextAlignmentCenter];
[wholeSale setBackgroundColor:[UIColor whiteColor]];
wholeSale.contentVerticalAlignment = UIControlContentHorizontalAlignmentCenter;
wholeSale.placeholder=#"Money";
[wholeSale setDelegate:self];
wholeSale.tag=102;
[cell.contentView addSubview:wholeSale];
cost = [[UITextField alloc] initWithFrame:CGRectMake(338, 0, 100, 32)];
cost.borderStyle = UITextBorderStyleLine;
cost.layer.borderWidth=2.0f;
cost.layer.borderColor=[UIColor colorWithRed:81/255.0 green:105/255.0 blue:169/255.0 alpha:(1)].CGColor;
cost.clipsToBounds=YES;
[cost setFont:[UIFont boldSystemFontOfSize:14]];
[cost setTextAlignment:UITextAlignmentCenter];
[cost setBackgroundColor:[UIColor whiteColor]];
cost.contentVerticalAlignment = UIControlContentHorizontalAlignmentCenter;
cost.placeholder=#"Cost";
[cost setDelegate:self];
cost.tag=103;
[cell.contentView addSubview:cost];
}
wholeSale=(UITextField*)[cell.contentView viewWithTag:102];
cost=(UITextField*)[cell.contentView viewWithTag:103];
}
-(void)textFieldDidEndEditing:(UITextField *)textField
{
// [textField resignFirstResponder];
UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
UITableView *table = (UITableView *)[cell superview];
NSIndexPath *textFieldIndexPath = [table indexPathForCell:cell];
NSLog(#"%d",textFieldIndexPath.row);
indexPathRow=textFieldIndexPath.row;
Products *record;
if (indexPathRow==[allProdutsData count]) {
NSManagedObjectContext *context = [appDelegate managedObjectContext]; // get AppDelegate's NSManagedObjectContext
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Products" inManagedObjectContext:context];
record = [[Products alloc] initWithEntity:entity insertIntoManagedObjectContext:nil];
NSLog(#"id==%d",[allProdutsData count]);
Products *lastFile=[allProdutsData lastObject];
NSLog(#"%#",[allProdutsData lastObject]);
[record setP_ID:[NSString stringWithFormat:#"%#",lastFile.p_ID]];
NSLog(#"%#",record);
}
else
{
NSLog(#"%d",indexPathRow);
// NSLog(#"%#",[allFilesData objectAtIndex:filesDateIndex]);
record=[allProdutsData objectAtIndex:indexPathRow];
NSLog(#"%#",record);
}
iif (textField.tag==102)
{
[record setSaleProduct:textField.text];
}
else if (textField.tag==103)
{
[record setCostProduct:textField.text];
}
[self addUpdateProducts:record recordNumber:indexPathRow];
[self animateTextField:textField up:NO];
}
This project does something similar to what you are trying to do. I recommend using it as an example.
You need the delegate of the textfield:
#interface ViewController () <UITextFieldDelegate>
then try this:
#implementation ViewController
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == self.myTextField) {
[self.myTextField resignFirstResponder];
}
return YES;
}
I have found solution for this problem
it was caused by reloading data.
for this purpose i try to reload data only when keyboard hide.
in viewDidLoad
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardDidShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
then use following methods
-(void)reloadData
{
[_nextAppointmentTableView reloadData];
// [_nextAppointmentTableView reloadData];
[self loadData];
}
- (void)keyboardDidShow:(NSNotification *)notification
{
}
- (void)keyboardWillHide:(NSNotification *)notification
{
[self performSelector:#selector(reloadData) withObject:nil afterDelay:0.5];
}

Detail Text for Tableview in popover in Iphone SDK

I open a PopOverview which contains a table View. It works fine But my cell also contain the detail Text which is not seen in table view cell when i open table view in popOver.
My code is as follow:
-(IBAction)btnTableMenu_TouchUpInside:(id)sender{
ListView *popUp=[[ListView alloc] initWithNibName:#"ListView" bundle:nil];
popoverController = [[UIPopoverController alloc]initWithContentViewController:popUp];
popoverController.delegate =self;
[popoverController setPopoverContentSize:CGSizeMake(300, 700)];
[popoverController presentPopoverFromRect:CGRectMake(150,25,20,50) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
How can i solve This??
Try this one :
Add the observer in the class where your popOverController view is
your popOverController class
yourPopOverControlle.m
-(void)viewdidLoad{
[[NSNotificationCenter defaultCenter]addObserver:self selector:#selector(removePopover:) name:#"hidePopOver" object:nil];
}
-(void)removePopover:(NSNotification *)notification{
[yourPopOver dismissPopoverAnimated:YES];
}
yourTableViewController.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[[NSNotificationCenter defaultCenter]postNotificationName:#"hidePopOver" object:nil];
}
To see detailed text label you need create you cell with UITableViewCellStyleSubtitle style;
For example :
- (UITableViewCell *)tableView:(UITableView *)_tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = nil;
cell = [_tableView dequeueReusableCellWithIdentifier:kTableCellIdentifier];
if(cell==nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kTableCellIdentifier] autorelease];
}
// configure cell
cell.textLabel.text = "text label text";
cell.detailTextLabel.text = "detailed text label text";
return cell;
}
see user167.. you just need to create new UITableViewcontroller for example DropDwnLevel1TableViewController.h, DropDwnLevel1TableViewController.m and xib right.
Now in DropDwnLevel1TableViewController Create IBOutlate of UITableVIew set one UITableView in to nib connect IBOUTLATE and set Delegate and dataSource
Now you can set created TableViewController add in to your UIPopoverViewcontroller like below method:-
-(IBAction)btnTableMenu_TouchUpInside:(id)sender{
DropDwnLevel1TableViewController *firstViewCtrl = [[DropDwnLevel1TableViewController alloc] init];
firstViewCtrl.title=#"My tableView";
UINavigationController *navbar = [[UINavigationController alloc] initWithRootViewController:firstViewCtrl];
[firstViewCtrl contentSizeForViewInPopover];
myPopOVer = [[UIPopoverController alloc] initWithContentViewController:navbar];
[navbar release];
myPopOVer.delegate = self;
myPopOVer.popoverContentSize =CGSizeMake(250,200);
[myPopOVer presentPopoverFromRect:sender.frame inView:sender.superview permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
}
FOR dismiss popOVer
In you class which declare popOverViewcontroller .m file ViewDidLoad method
- (void)viewDidLoad
{
// Hear creating NSNotificationCenter for dismiss popover
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(DismissPopOver:)
name:#"Dismiss"
object:nil];
[super viewDidLoad];
}
-(void)DismissPopOver:(NSNotification *)notification {
[yourPopOVer dismissPopoverAnimated:YES];
}
Now in DropDwnLevel1TableViewController.m didSelectRowAtIndexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// hear call NSNotificationCenter who creating in main class
[[NSNotificationCenter defaultCenter] postNotificationName:#"Dismiss" object:self];
}

Which addTarget actions can we take on UITextView?

I want to use addTarget:action on UITextView like on (UITextField or UIButton).
I want to call a method on UITextView.
please give some possible solution...
Thank You...
UITextView *TXT_First_Tag = [[UITextView alloc] initWithFrame:CGRectMake(5, textPosY, 350, 65)];
TXT_First_Tag.backgroundColor = [UIColor whiteColor];
TXT_First_Tag.font = [UIFont fontWithName:#"Arial-BoldMT" size:30.0];
TXT_First_Tag.editable =YES;
TXT_First_Tag.tag = i;
TXT_First_Tag.textColor = [UIColor blackColor];
[TXT_First_Tag addTarget:self action:#selector(C6Loop) forControlEvents:UIControlEventEditingDidEnd]; // This Line I want to use, it's working fine on textfield...
[scrollview addSubview:TXT_First_Tag];
We use UITextView delegate methods for this purpose.
Put this in your code.
UITextView *TXT_First_Tag = [[UITextView alloc] initWithFrame:CGRectMake(5, textPosY, 350, 65)];
TXT_First_Tag.backgroundColor = [UIColor whiteColor];
TXT_First_Tag.font = [UIFont fontWithName:#"Arial-BoldMT" size:30.0];
TXT_First_Tag.editable =YES;
TXT_First_Tag.delegate = self;
TXT_First_Tag.tag = i;
TXT_First_Tag.textColor = [UIColor blackColor];
[scrollview addSubview:TXT_First_Tag];
- (void)textViewDidBeginEditing:(UITextView *)textView{
NSLog(#"Begin editing");
}
- (void)textViewDidEndEditing:(UITextView *)textView{
NSLog(#"DidEndEditing");
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
NSLog(#"ShouldBeginEditing");
return TRUE;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
NSLog(#"ShouldEndEditing");
return TRUE;
}
If your controller implements the UITextViewDelegate protocol, you can then set the controller as the text view's delegate in the controller's instance method, viewDidLoad():
yourTextView.delegate = self;
Then, if you want to perform a task before editing your text view, use:
-(void)textViewDidBeginEditing:(UITextView *)textView {}
And, if you want to do a task after editing your text view, use:
-(void)textViewDidEndEditing:(UITextView *)textView {}
Surely a better way of getting the "editing did end" message is by implementing the UITextViewDelegate?
TXT_First_Tag.delegate = self;
...
- (void)textViewDidEndEditing:(UITextView *)textView {
// stuff you'd put in C6Loop
Chaps,
Even though your responses did not directly solve my problem, it helped me narrow it down.
I have textviews in each cell and needed to pass which text view was being edited so I could update the database.
In a nutshell I set each textview tag in each cell to the indexpath.row. I then reference that cell in the delegate by textview.tag
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:#"frontCell" owner:self options:nil];
cell = mainPageCell;
self.mainPageCell = nil;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
UITextView *trackDetails;
trackDetails = (UITextView *)[cell viewWithTag:22];
trackDetails.text = [[myArray objectAtIndex:indexPath.row] objectAtIndex:0];
trackDetails.delegate = self;
trackDetails.tag = indexPath.row;
}
- (void)textViewDidEndEditing:(UITextView *)textView
{
NSLog(#"%d",textView.tag);
UPDATE DATABASE WITH CHANGED TEXT
[textView resignFirstResponder];
[self.tableView reloadData];
}

How to pass the state of button object to another class when the tableview is in edit mode in iPhone?

I have a tableview controller which consists of a button with an image on it and 2 labels. When I change the tableview to edit mode, I want my button to perform an action i.e such that when I click on my button in edit mode it should change its image. I have an editcontroller class when the didselectrow of first table is clicked it opens a new class i.e editcontroller.
In this controller class, I have a switch button. When the button image of the first tableview is changed to 'OFF' the the switchbutton in the editcontroller should also changed to 'OFF' and when the switchbutton of the editcontroller is changed to 'ON' then the button image should change to 'ON'.
This is my first tableview code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:#"Cell%d%d", indexPath.section, indexPath.row];
appDelegate = (StopSnoozeAppDelegate*)[[UIApplication sharedApplication]delegate];
TAlarmCell *cell =(TAlarmCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[TAlarmCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
mimageButton = [UIButton buttonWithType:UIButtonTypeCustom];
mimageButton.frame=CGRectMake(10, 20, 20, 20);
mimageButton.tag = 1;
[mimageButton setImage:[UIImage imageNamed:#"alarm_ON.png"] forState:UIControlStateNormal];
[mimageButton setImage:[UIImage imageNamed:#"alarm_OF.png"] forState:UIControlStateSelected];
[cell.contentView addSubview:mimageButton];
[mimageButton addTarget:self action:#selector(changeMapType:) forControlEvents: UIControlEventTouchUpInside];
}
[appDelegate.dateFormatter setDateFormat:#"hh:mm a"];
cell.accessoryType = UITableViewCellAccessoryNone;
return cell;
}
In the editing code I have done this code
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[mTableView setEditing:editing animated:YES];
if (editing)
{
[mimageButton addTarget:self action:#selector(changeMapType:) forControlEvents: UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = nil;
editimage = YES;
[self.mTableView reloadData];
}
else {
editimage = NO;
self.navigationItem.rightBarButtonItem = addButton;
if (appDelegate.snoozearray)
{
[appDelegate.snoozearray release];
}
appDelegate.snoozearray = [[NSMutableArray alloc]init];
[Alarm getInitialDataToDisplay:[appDelegate getDBPath]];
[self.mTableView reloadData];
}
}
This is my imagebutton action code
-(void)changeMapType:(UIButton *)sender
{
NSIndexPath *indexPath =[self.tableView indexPathForCell:(UITableViewCell *)[[sender superview] superview]];
NSUInteger row = indexPath.row;
NSLog(#"row...%d",row);
appDelegate.changeimagetype = !appDelegate.changeimagetype;
sender.selected = appDelegate.changeimagetype;
[self.tableView reloadData];
}
Your explanation is not totally clear, but I get the idea of what you want to achieve.
You should use [NSNotification defaultCentre].
This is how it works. Suppose I have a class A, in which I have a button X, which I want to change its text when in my another class B. I click to change Button.
So these are the steps:
1)In viewDidLoad of A
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(ChangeButton) name:#"Change Button" object:nil]
2) In Dealloc of A
[[NSNotificationCenter defaultCenter] removeObserver:self];
3) In B..when you click to change Button after that put this line
[[NSNotificationCenter defaultCenter] postNotificationName:#"Change Button" object:nil userInfo:nil];
In the end, ChangeButton method (in A) will be called when click button is done in B make sure you define a method ChangeButton in A.
Post a notification when the switch value changes and then in the other view, you will get that notification..and then change the button in respond to notification.

Ipad orientation issue - UITextView reloads and keyboard disappears

While I was running my application on simulator everything was working fine. Including the orientation of all views. Now, when I tested the application on my Ipad, I noticed an issue which I think I must take care of.
I have a UITableView which has a UILabel, UITextView and a UIButton in each of its row. The problem I am facing is, when I type something on the textview, and in between change the orientation, the text disappears along with the keyboard. Although I know the reason for this is the reloading of tableview which I do every time I change the orientation, I am not able to handle it. Reloading of tableview is also important for other views to be oriented properly.
What needs to be done?
Update
- (void)viewDidLoad
{
[super viewDidLoad];
checkTextView = FALSE;
self.title=#"Tasks";
arrTextViews = [[NSMutableArray alloc]init];
[self checkOrientation];
// Do any additional setup after loading the view from its nib.
}
-(void)viewWillAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(receivedRotate:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
-(void)viewWillDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
}
-(void) checkOrientation
{
UIInterfaceOrientation orientation = self.interfaceOrientation;
#try
{
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
textXX=340.0;
btnXX=900.0;
textLL=480.0;
[commentsTable reloadData];
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
textXX=240.0;
btnXX=650.0;
textLL=350.0;
[commentsTable reloadData];
}
}
#catch (NSException *ex) {
[Utils LogExceptionOnServer:#"TodayViewController" methodName:#"checkOrientation" exception:[ex description]];
}
}
- (void)receivedRotate:(NSNotification *)notification
{
[self checkOrientation];
}
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [arrComments count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
}
cell.selectionStyle=UITableViewCellSelectionStyleNone;
// Configure the cell
NSArray *arrSeparate = [strName componentsSeparatedByString:#":"];
NSString *str1 = [arrSeparate objectAtIndex:0];
NSString *str2 = [arrSeparate objectAtIndex:1];
lblName1=[[UILabel alloc]init];
lblName1.frame=CGRectMake(10, 13, 200, 30);
lblName1.numberOfLines=1;
[lblName1 setText:str1];
[lblName1 setTextColor:[UIColor colorWithRed:0.0/255.0 green:73.0/255.0 blue:121.0/255.0 alpha:1.0]];
[lblName1 setFont:[UIFont boldSystemFontOfSize:25.0]];
[lblName1 setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:lblName1];
[lblName1 release];
lblName2=[[UILabel alloc]init];
lblName2.frame=CGRectMake(10, 50, 200.0, 70);
lblName2.numberOfLines=2;
[lblName2 setText:str2];
[lblName2 setTextColor:[UIColor colorWithRed:0.0/255.0 green:73.0/255.0 blue:121.0/255.0 alpha:1.0]];
[lblName2 setFont:[UIFont boldSystemFontOfSize:25.0]];
[lblName2 setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:lblName2];
[lblName2 release];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(textXX-1, 12, textLL+2, 132)];
imgView.image = [UIImage imageNamed:#"box.png"];
[cell.contentView addSubview:imgView];
[imgView release];
//txtComment
txtComment = [[UITextView alloc] initWithFrame:CGRectMake(textXX,13, textLL, 130)];
txtComment.scrollEnabled = YES;
txtComment.userInteractionEnabled = YES;
txtComment.tag=indexPath.row;
iTextViewTag = txtComment.tag;
strGetText = txtComment.text;
[txtComment setTextColor:[UIColor colorWithRed:0.0/255.0 green:73.0/255.0 blue:121.0/255.0 alpha:1.0]];
[txtComment setFont:[ UIFont boldSystemFontOfSize: 25 ]];
[cell.contentView addSubview:txtComment];
[arrTextViews addObject:txtComment];
[txtComment release];
UIImageView *imgBtn = [[UIImageView alloc] initWithFrame:CGRectMake(btnXX-1, 12, 72, 132)];
imgBtn.image = [UIImage imageNamed:#"commentbbtnbox.png"];
[cell.contentView addSubview:imgBtn];
[imgBtn release];
//btnClose
btnClose = [UIButton buttonWithType:UIButtonTypeCustom];
btnClose.frame=CGRectMake(btnXX, 13,70,130);
btnClose.tag= indexPath.row;
btnClose.backgroundColor = [UIColor grayColor];
[btnClose addTarget:self action:#selector(btnCloseAction:) forControlEvents:UIControlEventTouchDown];
[cell.contentView addSubview:btnClose];
return cell;
}
One solution (maybe not the best) would be to save the text and the indexPath of the row being edited just before the rotation occurs. When the rotation is finished, you'll just have to restore the text and the focus. Use the following messages in your tableview controller:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
See here, if these messages are not called.