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.
Related
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];
}
I need help with this. I have updated xcode to the latest and when I try to get test, the old code throws an error "class is not key value coding-compliant for the key scrollView."
Funny thing is that there is no scrollview in this. I have other views almost exact code and it works fine. Here is the code. there is no nib for this either so the taking out the scrollview from the view won't work.
#import "pearGalleryController.h"
#import "pearGallery.h"
#implementation pearGalleryController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:100];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.navigationItem.title = #"Variety of Pears";
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 3;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
return 122;
}
// 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 is an object of the UITableViewCell this assign an object to a cell 2 memory areas, o need to auto release on the alloc bcause it is an object
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
// Set up the cell...
int picIndex = [indexPath row]*3;
UIButton* tempView = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 107,123)];
[tempView setImage:[UIImage imageNamed:[NSString stringWithFormat:#"pears_%d.png",picIndex]]
forState:UIControlStateNormal];
tempView.tag = picIndex;
[tempView addTarget:self action:#selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:tempView];
[tempView release];
tempView = [[UIButton alloc]initWithFrame:CGRectMake(106, 0, 107,123)];
[tempView setImage:[UIImage imageNamed:[NSString stringWithFormat:#"pears_%d.png",picIndex+1]]
forState:UIControlStateNormal];
tempView.tag = picIndex+1;
[tempView addTarget:self action:#selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:tempView];
[tempView release];
tempView = [[UIButton alloc]initWithFrame:CGRectMake(212, 0, 107,123)];
[tempView setImage:[UIImage imageNamed:[NSString stringWithFormat:#"pears_%d.png",picIndex+2]]
forState:UIControlStateNormal];
tempView.tag = picIndex+2;
[tempView addTarget:self action:#selector(buttonClick:)
forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:tempView];
[tempView release];
return cell;
}
-(void)buttonClick:(id)sender
{
UIButton* btn = (UIButton*)sender;
int index = btn.tag;
pearGallery *anotherViewController = [[pearGallery alloc] initWithNibName:#"pearGallery" bundle:[NSBundle mainBundle]];
anotherViewController.myIndex = index;
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
//UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"video.png"] style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)dealloc {
[super dealloc];
}
#end
and the h file
#import
#interface pearGalleryController : UITableViewController {
}
#end
probably a dangling reference in your xib file, check to make sure references are cleared.
Usually this error occurs when you have an object , in your case it is the 'scrollView' which is attached via the interface builder to the scrollView item in storyboard/xib.
Check your links in interface builder ( furthest tab to the right ) and that you don't have a duplicate link to another IBOutlet.
I find this only occurs to me when I link an object up then 'mistype' my link , I go to change it but don't remove the old link from interface builder ie SCrollview and scroLLview2
Go to your interface builder ( connection tab ) and check you don't have duplicate links.
Remove all links to your 'scrollview' and 're link' to your .h file then try again
you may have typed scrollView then changed it to scrollview and not realised..good luck
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 made an UITableView and I am fetching data from JSON from a webservice.
Firat, I want that I get first 5 objects first and load them in my tableView. That is happening properly.
Then I want that whenever the user scrolls to the footer ..the next 5 objects should be fetched and it should be shown in tableView..
I am stuck here ..can anyone give me any idea how to proceed next?
My tableview has all custom cells loading from the custom classes for different types?
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if(section==[array count]-1)
{
UITableViewCell *cell = [self tableView:mtableview1 cellForRowAtIndexPath:myIP];
frame = cell.contentView.frame;
footerView = [[UIView alloc] init];
footerView.backgroundColor=[UIColor clearColor];
self.activityIndicator = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
self.activityIndicator.hidesWhenStopped=YES;
self.activityIndicator.center = CGPointMake(65,50);
[self.activityIndicator startAnimating];
UILabel* loadingLabel = [[UILabel alloc]init];
loadingLabel.font=[UIFont boldSystemFontOfSize:12.0f];
loadingLabel.textAlignment = UITextAlignmentLeft;
loadingLabel.textColor = [UIColor colorWithRed:87.0/255.0 green:108.0/255.0 blue:137.0/255.0 alpha:1.0];
loadingLabel.numberOfLines = 0;
loadingLabel.text=#"Loading.......";
loadingLabel.frame=CGRectMake(95,35, 302,25);
loadingLabel.backgroundColor =[UIColor clearColor];
loadingLabel.adjustsFontSizeToFitWidth = NO;
[footerView addSubview:self.activityIndicator];
[footerView addSubview:loadingLabel];
[self performSelector:#selector(loadending) withObject:nil afterDelay:1.0];
[loadingLabel release];
NSLog(#"%f",mtableview1.contentOffset.y);
mtableview1.tableFooterView=footerView;
return footerView;
}
return nil;
}
I have been doing it like this, but its position is not correct all the time. That's my big issue.
You can use the below concept.Concept is when user pull the table view then reload the additional data like pull to refresh.
Code Sample :
//MARK: -UIScrollViewDelegate
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
if (scrollView.contentOffset.y <= - 65.0f) {
// fetch extra data & reload table view
}
}
Use UIScrollViewDelegate Methods
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
}
in scrollViewDidScroll Method you can check row index for call you loading method
NSIndexPath *indexPath = [[self.myTable indexPathsForVisibleRows]objectAtIndex:1]; //in middle visible of row
int visibleRowIndex = indexPath.row;
I already implement this please look this here is my code
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if(footerView == nil)
{
footerView = [[UIView alloc] init];
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if (ObjApp.checkDevice == 1)
{
UIImage *image = [[UIImage imageNamed:#"LoadMoreBtn.png"]
stretchableImageWithLeftCapWidth:8 topCapHeight:8];
btnLoadMore = [UIButton buttonWithType:UIButtonTypeCustom];
[btnLoadMore setBackgroundImage:image forState:UIControlStateNormal];
if(screenBounds.size.height == 568)
{
// iPhone 5
[btnLoadMore setFrame:CGRectMake(74, 13, 148, 34)];
}
else
{
// iPohne 4 and Older iPhones
[btnLoadMore setFrame:CGRectMake(74, 13, 148, 34)];
}
}
else if (ObjApp.checkDevice == 2)
{
UIImage *image = [[UIImage imageNamed:#"LoadMoreBtn_iPad.png"]
stretchableImageWithLeftCapWidth:8 topCapHeight:8];
btnLoadMore = [UIButton buttonWithType:UIButtonTypeCustom];
[btnLoadMore setBackgroundImage:image forState:UIControlStateNormal];
[btnLoadMore setFrame:CGRectMake(220, 26, 296, 67)];
}
[btnLoadMore.titleLabel setFont:[UIFont boldSystemFontOfSize:20]];
[btnLoadMore setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[btnLoadMore addTarget:self action:#selector(btnLoadmore_clicked:)
forControlEvents:UIControlEventTouchUpInside];
[footerView addSubview:btnLoadMore];
}
return footerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (ObjApp.checkDevice == 1)
{
return 47;
}
else
{
return 100;
}
return 0;
}
#pragma mark - Button Click Methods
-(void)btnLoadmore_clicked:(id)sender
{
if(page > 0)
{
sendpage++;
if(sendpage<= page)
{
[self loading];
NSString *urlString = [NSString stringWithFormat:#"data={\"name\":\"%#\",\"lat\":\"%f\",\"page\":\"%d\",\"long\":\"%f\"}",txtSearchFld.text,ObjApp.current_Latitude,sendpage,ObjApp.current_Longitude];
[WebAPIRequest WS_Search:self :urlString];
CGFloat height = tblSearchResult.contentSize.height - tblSearchResult.bounds.size.height;
[tblSearchResult setContentOffset:CGPointMake(0, height) animated:YES];
}
}
}
You can increase Number of rows In table View when you reach to the last row check do you have more content to show or not. If u have MOre content to show then increase number of rows.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
After increasing number of row you can scroll to the desired row which you wann to show...
I have a custom UITableViewCell as such:
#implementation CellWithThreeSubtitles
#synthesize title, subTitle1, subTitle2, subTitle3;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.textLabel.backgroundColor = self.backgroundColor;
self.textLabel.opaque = NO;
self.textLabel.textColor = [UIColor blackColor];
self.textLabel.highlightedTextColor = [UIColor whiteColor];
self.textLabel.font = [UIFont boldSystemFontOfSize:22.0];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect contentRect = self.contentView.bounds;
CGRect frame = CGRectMake(35.0, 0, contentRect.size.width, 50.0);
self.textLabel.frame = frame;
UILabel *subLabel1 = [[UILabel alloc] init];
frame = CGRectMake(35.0, 34.0, contentRect.size.width, 25.0);
subLabel1.font = [UIFont systemFontOfSize:18.0];
subLabel1.backgroundColor = [UIColor clearColor];
subLabel1.text = subTitle1;
subLabel1.opaque = NO;
subLabel1.frame = frame;
[self.contentView addSubview:subLabel1];
UILabel *subLabel2 = [[UILabel alloc] init];
frame = CGRectMake(35.0, 54.0, contentRect.size.width, 25.0);
subLabel2.font = [UIFont boldSystemFontOfSize:18.0];
subLabel2.backgroundColor = [UIColor clearColor];
subLabel2.text = subTitle2;
subLabel2.opaque = NO;
subLabel2.frame = frame;
[self.contentView addSubview:subLabel2];
UILabel *subLabel3 = [[UILabel alloc] init];
frame = CGRectMake(contentRect.size.width-100.0, 54.0, contentRect.size.width, 25.0);
subLabel3.font = [UIFont systemFontOfSize:18.0];
subLabel3.backgroundColor = [UIColor clearColor];
subLabel3.text = subTitle3;
subLabel3.opaque = NO;
subLabel3.frame = frame;
[self.contentView addSubview:subLabel3];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)dealloc {
[super dealloc];
[subTitle4 release];
[subTitle3 release];
[subTitle2 release];
[subTitle1 release];
[title release];
}
When I implement it in my UITableView like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
int section = [indexPath indexAtPosition:0];
static NSString *kCustomCellID = #"AppointmentCellID";
CellWithThreeSubtitles *cell = (CellWithThreeSubtitles *)[tableView dequeueReusableCellWithIdentifier:kCustomCellID];
if (cell == nil) {
cell = (CellWithThreeSubtitles *)[[[CellWithThreeSubtitles alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCustomCellID] autorelease];
}
switch (section) {
case 0:
if ([wineArray count]==0) {
cell.textLabel.text = #"No wine favorites selected yet";
}else{
cell.subTitle1 = [[wineArray objectAtIndex:indexPath.row] objectForKey:#"Varietal"];
cell.subTitle2 = [NSString stringWithFormat:#"Bin No. %#", [[wineArray objectAtIndex:indexPath.row] objectForKey:#"Bin"]];
cell.subTitle3 = [NSString stringWithFormat:#"$%#", [[wineArray objectAtIndex:indexPath.row] objectForKey:#"Price"]];
cell.textLabel.text = [NSString stringWithFormat:#"%# (%#)", [[wineArray objectAtIndex:indexPath.row] objectForKey:#"Name"], [[wineArray objectAtIndex:indexPath.row] objectForKey:#"Availability"]];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.userInteractionEnabled = NO;
break;
case 1:
if ([dinnerArray count]==0)
cell.textLabel.text = #"No dinner favorites selected yet";
else
cell.textLabel.text = [NSString stringWithFormat:#"%#", [[dinnerArray objectAtIndex:indexPath.row] objectForKey:#"Name"]];
break;
}
return cell;
}
the contents of the cell duplicates on top of itself every time the orientation of the device changes. Is it redrawing the cell every time the device rotates? And if so, How can I keep it from doing so?
You should be creating the subviews and adding them to your cell's subviews array in your -initWithStyle:reuseIdentifier: method. You only need to create the subviews once. The -layoutSubviews method is invoked repeatedly by the framework whenever the device orientation changes, to allow you to resize and/or move the subviews (plus make any other minor adjustments) to compensate for differences between the orientations.
I suspect layoutSubViews is being called on rotation, and re-drawing new labels on top of your old ones. If you remove any labels from the table cell at the beginning of layoutSubViews that would probably fix that issue, or you could create them in the init and then just position them in layoutSubViews.