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];
}
Related
I have a table view with custom cells ,there are uibuttons on custom cell ,if i select button except that cell remaining all cells should be grayouted or disabled is it possible.
// code in tableview class
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
{
NSLog(#"No OF rows:%d",[contents count]);
return [contents count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
{
static NSString *cellIdentifier = #"cell";
// Try to retrieve from the table view a now-unused cell with the given identifier.
cell = (uploadCustomCell *)[tableView dequeueReusableCellWithIdentifier:#"uploadCustomCell"];
if (cell == nil) {
NSLog(#"cell allocated");
// Use the default cell style.
cell = [[uploadCustomCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"uploadCustomCell"];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"uploadCustomCell"
owner:self options:nil];
cell = [nib objectAtIndex:0];
}
saveBtnCcell.hidden = YES;
cell.textNamefield.hidden = YES;
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell.defaultSwitch setEnabled:NO];
dictionaryContents = [contents objectAtIndex:indexPath.row];
NSLog(#"dict dict :%#",dictionaryContents);
//
cell
.nameLabelCell.text = [dictionaryContents valueForKey:#"VideoName"];
cell.userName.text = [dictionaryContents valueForKey:#"User"];
NSLog(#"Array Image:%#",arrayimage);
cell.thumbImg.image = [arrayimage objectAtIndex:indexPath.row];
NSLog(#"ARimage:%#,index%d",[arrayimage objectAtIndex:indexPath.row],indexPath.row);
NSString *defaultVideo = [dictionaryContents valueForKey:#"DefaultVideo"];
NSLog(#"Default Video:%#",defaultVideo);
if ([defaultVideo isEqual: #"1"]) {
// [cell.defaultSwitch setOn:YES animated:YES];
[defaultSwitche setOn:YES animated:YES];
}
else{
// [cell.defaultSwitch setOn:NO animated:YES];
[defaultSwitche setOn:NO animated:YES];
}
[cell.defaultSwitch addTarget:self action:#selector(setState:) forControlEvents:UIControlEventValueChanged];
VideoNameTextField.hidden = YES;
return cell;
}
// Code in customcell
#interface uploadCustomCell (){
UploadAllViewController *uploadAll;
}
#end
#implementation uploadCustomCell
#synthesize textNamefield;
#synthesize savebtn,edit,nameLabelCell,textLabel,uploadBTN;
#synthesize defaultSwitch;
//#synthesize uploadAll;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)dealloc {
[_userName release];
[_thumbImg release];
//[savebtn release];
[textNamefield release];
[nameLabelCell release];
[_test release];
[savebtn release];
[defaultSwitch release];
[uploadBTN release];
[super dealloc];
}
- (IBAction)editAction:(id)sender {
[uploadBTN setEnabled:NO];
uploadAll = [[UploadAllViewController alloc]init];
CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:uploadAll.tabelView1];
NSIndexPath *indexPath = [uploadAll.tabelView1 indexPathForRowAtPoint:buttonPosition];
int no = indexPath.row;
NSLog(#"index path :%d",no);
[uploadAll didEditButtonPressed:self];
}
- (IBAction)saveBtnAction:(id)sender {
[uploadBTN setEnabled:YES];
[uploadAll didSaveButtonPressed:self];
}
when i select this editAction: except that cell remaining cells should be grayouted.
In your cellForRowAtIndexPath you have to account for the state of your table view, i.e. if one or zero cells are selected. Use that to change the appearance of your cell as you wish. In the example below I have assumed you are having a straight array without any sections, but the same principle would work with indexPaths as well. I use an int selectedRow set to -1 if there is no cell selected.
#define kNoCellSelected -1
// in cellForRowAtIndexPath:
if (self.selectedRow == kNoCellSelected) {
cell.backgroundView.backgroundColor = normalColor;
cell.userInteractionEnabled = YES;
}
else if (self.selectedRow != indexPath.row) {
cell.backgroundView.backgroundColor = disabledColor;
cell.userInteractionEnabled = NO;
}
Don't forget to set selectedRow in didSelectRowAtIndexPath: and in viewDidLoad.
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];
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.
My UITableViewCell has UITextField inside, now I want to get UITextField data to be stored in database (using insert command) but how can I be able to access the UITableViewCell's UITextField data
#interface ELCTextfieldCell : UITableViewCell <UITextFieldDelegate> {
id delegate;
UILabel *leftLabel;
UITextField *rightTextField;
NSIndexPath *indexPath;
}
#implementation ELCTextfieldCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
leftLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[leftLabel setBackgroundColor:[UIColor clearColor]];
[leftLabel setTextColor:[UIColor colorWithRed:.285 green:.376 blue:.541 alpha:1]];
[leftLabel setFont:[UIFont fontWithName:#"Helvetica" size:12]];
[leftLabel setTextAlignment:UITextAlignmentRight];
[leftLabel setText:#"Left Field"];
[self addSubview:leftLabel];
rightTextField = [[UITextField alloc] initWithFrame:CGRectZero];
rightTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[rightTextField setDelegate:self];
[rightTextField setPlaceholder:#"Right Field"];
[rightTextField setFont:[UIFont systemFontOfSize:17]];
// FOR MWF USE DONE
[rightTextField setReturnKeyType:UIReturnKeyDone];
[self addSubview:rightTextField];
}
return self;
}
//Layout our fields in case of a layoutchange (fix for iPad doing strange things with margins if width is > 400)
- (void)layoutSubviews {
[super layoutSubviews];
CGRect origFrame = self.contentView.frame;
if (leftLabel.text != nil) {
leftLabel.frame = CGRectMake(origFrame.origin.x, origFrame.origin.y, 90, origFrame.size.height-1);
rightTextField.frame = CGRectMake(origFrame.origin.x+105, origFrame.origin.y, origFrame.size.width-120, origFrame.size.height-1);
} else {
leftLabel.hidden = YES;
NSInteger imageWidth = 0;
if (self.imageView.image != nil) {
imageWidth = self.imageView.image.size.width + 5;
}
rightTextField.frame = CGRectMake(origFrame.origin.x+imageWidth+10, origFrame.origin.y, origFrame.size.width-imageWidth-20, origFrame.size.height-1);
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if([delegate respondsToSelector:#selector(textFieldDidReturnWithIndexPath:)]) {
[delegate performSelector:#selector(textFieldDidReturnWithIndexPath:) withObject:indexPath];
}
return YES;
}
- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *textString = self.rightTextField.text;
if (range.length > 0) {
textString = [textString stringByReplacingCharactersInRange:range withString:#""];
}
else {
if(range.location == [textString length]) {
textString = [textString stringByAppendingString:string];
}
else {
textString = [textString stringByReplacingCharactersInRange:range withString:string];
}
}
if([delegate respondsToSelector:#selector(updateTextLabelAtIndexPath:string:)]) {
[delegate performSelector:#selector(updateTextLabelAtIndexPath:string:) withObject:indexPath withObject:textString];
}
return YES;
}
#interface RootViewController : UITableViewController <ELCTextFieldDelegate> {
NSArray *labels;
NSArray *placeholders;
}
#implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.labels = [NSArray arrayWithObjects:#"First Name",
#"Last Name",
#"Email",
#"Phone Number",
nil];
self.placeholders = [NSArray arrayWithObjects:#"Enter First Name",
#"Enter Last Name",
#"Enter Email",
#"Phone Number (Optional)",
nil];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
ELCTextfieldCell *cell = (ELCTextfieldCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[ELCTextfieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
Try setting tag value to the textField and then retrieve the values.
Ex: rightTextField.tag = 1000; // don't use 0
Access the textField using,
UITextField *textField = (UITextField *)[self.view viewWithTag:1000];
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.