Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7177145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:39:05+00:00 2026-05-28T16:39:05+00:00

i created an iPad application, in which i used searchBar, in searchBar data is

  • 0

i created an iPad application, in which i used searchBar, in searchBar data is coming from database, and i am storing it in an array called tableData.

After this i am passing this tabledata array to tableView called myTableView, i declared height of table view in didLoad method.

I want height of tableView to be dynamic according to number of elements in table,

here is the code snippet,

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    // only show the status bar’s cancel button while in edit mode

    sBar.autocorrectionType = UITextAutocorrectionTypeNo;
    // flush the previous search content
    [tableData removeAllObjects];
}


- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
    sBar.showsCancelButton = NO;
    [myTableView setHidden:TRUE];
}


- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    [myTableView setHidden:FALSE];
    [tableData removeAllObjects];// remove all data that belongs to previous search
    myTableView.backgroundColor=[[UIColor alloc]initWithRed:4.0 / 255 green:24.0 / 255 blue:41.0 / 255 alpha:1.0];


    [self.view bringSubviewToFront:myTableView];

    if([searchText isEqualToString:@""]||searchText==nil){
        [myTableView setHidden:TRUE];
        [myTableView reloadData];
        return;
    }
    NSInteger counter = 0;
    for(NSString *name in arr)
    {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
        NSRange r = [name rangeOfString:searchText options:NSCaseInsensitiveSearch];

        if(r.location != NSNotFound)
        {
            if(r.location== 0)//that is we are checking only the start of the naames.
            {
                [tableData addObject:name];
            }
        }
        counter++;
        [pool release];
    }
    [myTableView reloadData];
}


- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
    // if a valid search was entered but the user wanted to cancel, bring back the main list content
    [tableData removeAllObjects];

    @try{
        [myTableView reloadData];
    }
    @catch(NSException *e){
    }
    [sBar resignFirstResponder];
    sBar.text = @"";
}


// called when Search (in our case “Done”) button pressed
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{

    [searchBar resignFirstResponder];
    [myTableView reloadData];
}

declaration of myTableView in didLoad:

myTableView.frame=CGRectMake(550, 00, 220,400);

see screenshot,
in first image data is there but, tableView doesn’t increases it’s size and in second image only 1 data is there but height is still fix.

screen
screen

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T16:39:06+00:00Added an answer on May 28, 2026 at 4:39 pm

    As Atulkumar V. Jain said try this: in the - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText method resize the table’s frame as followed:

    CGRect frame = myTableView.frame;
    frame.size.height = MIN(40 * [tableData count], 400); // 400 is the maximum height that the table view can have. You can change it to whatever you like
    myTableView.frame = frame;
    

    Let me know if that works for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i created an iPad application, in which i am fetching data from URL, when
I created an iPad application in which I would like to have my searchBar
I have created an iPad application which contains images. I am storing these images
Possible Duplicate: Convert ipad application to iphone. Universal app I created one application which
I have created a application which uses Sqlite database. Now i wanted to deploy
i created an iPad application, in which navigation is not working, for example on
I have created iPad application which downloads images using web service. But my application
I'm trying to create an objective C classe for my iPad application which can
i am new to iPad developer, i have created two or three iPad application
i am new to iPad developer, i have created two or three iPad application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.