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

  • Home
  • SEARCH
  • 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 9158301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:12:52+00:00 2026-06-17T13:12:52+00:00

I’m loading two tableViews separately one after the other in a same view (ScrollView).But

  • 0
  1. I’m loading two tableViews separately one after the other in a same view (ScrollView).But after loading them when I try to scroll the first tableView then its cell(1st and last) contents are changed to second tableViews cell(1st and last) content.Couldn’t understand where I m going wrong?

This is the code Im working on:

- (void)viewDidLoad
{
      self.tableView1=[[UITableView alloc] initWithFrame:CGRectMake(10,10,310,250) style:UITableViewStylePlain];
        self.tableView1.delegate=self;
        self.tableView1.dataSource=self;
        self.tableView1.rowHeight=80;
        self.tableView1.scrollEnabled = YES;
        currenttableView=@"1";
        [testscroll addSubview:self.tableView1];
 [self performSelector:@selector(callWebserviceMethod) withObject:nil afterDelay:0];
}
-(void)callWebserviceMethod
{
  self.tableView2=[[UITableView alloc] initWithFrame:CGRectMake(10,self.tableView1.frame.origin.y+self.tableView1.frame.size.height+6,310,230) style:UITableViewStylePlain];
        self.tableView2.delegate=self;
        self.tableView2.dataSource=self;
        self.tableView2.rowHeight=80;
         currenttableView=@"2";
        self.tableView2.scrollEnabled = YES;
        [testscroll addSubview:self.tableView2];
}


- (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]autorelease];

    }
    cell.accessoryType= UITableViewCellAccessoryDetailDisclosureButton;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;


    if(currenttableView==@"1")
    {


        cell.textLabel.text = [[filtered objectAtIndex:indexPath.row] objectForKey:@"CompanyName"] ;   //filtered is NSMutableArray
        cell.textLabel.tag=3;
        cell.textLabel.font=[UIFont boldSystemFontOfSize:12];


        UIButton *showDirections = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        showDirections.frame = CGRectMake(10.0f, 52.0f, 85.0f, 20.0f);
        [showDirections setTitle:@"Direction" forState:UIControlStateNormal];
        [showDirections setTag:indexPath.row];
        [showDirections.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
        showDirections.backgroundColor=[UIColor lightTextColor];
        [ showDirections setBackgroundImage:[UIImage imageNamed:@"background-button.png"] forState:UIControlStateNormal];
        showDirections.titleLabel.textColor=[UIColor whiteColor];

        [cell addSubview:showDirections];
        [showDirections addTarget:self action:@selector(showDirectionsfordC:)forControlEvents:UIControlEventTouchUpInside];



        return cell;

    }


     if(currenttableView==@"2")
    {


        cell.textLabel.text = [[places objectAtIndex:indexPath.row] objectForKey:@"name"] ;    //places is NSMutableArray
        cell.textLabel.lineBreakMode=UILineBreakModeWordWrap;
        cell.textLabel.numberOfLines=0;
        cell.textLabel.font=[UIFont boldSystemFontOfSize:12];
        cell.textLabel.tag=3;




        UIButton *showDirections = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        showDirections.frame = CGRectMake(10.0f, 52.0f, 85.0f, 20.0f);
        [showDirections setTitle:@"Direction" forState:UIControlStateNormal];
        [showDirections setTag:indexPath.row];
        [showDirections.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
        showDirections.backgroundColor=[UIColor lightTextColor];
        [ showDirections setBackgroundImage:[UIImage imageNamed:@"background-button.png"] forState:UIControlStateNormal];
        showDirections.titleLabel.textColor=[UIColor whiteColor];

        [cell addSubview:showDirections];
        [showDirections addTarget:self action:@selector(showDirections:)forControlEvents:UIControlEventTouchUpInside];

        NSString *vicinity1 = [[places objectAtIndex:indexPath.row]objectForKey:@"vicinity"];
        UILabel *vicinity = [[UILabel alloc]initWithFrame:CGRectMake(10, 45, 320, 10)];
        vicinity .font=[UIFont fontWithName:@"TimesNewRomanPS-BoldMT" size:12];
        [vicinity  setTextAlignment:UITextAlignmentLeft];
        vicinity.text=[NSString stringWithFormat:@"%@",vicinity1];

        vicinity.tag=4;
        [cell addSubview:vicinity ];
        vicinity.hidden=YES;
        [vicinity release];

        return cell;



    }

    }

Where I m going wrong?

2.. When tableView2 is empty then ScrollView loads with only tableView1.Then at that time when I try to scroll tableView1 then I m getting error :Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
at this line of tableView2

cell.textLabel.text = [[places objectAtIndex:indexPath.row] objectForKey:@"name"] ;//error

How can I get it going?

  • 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-06-17T13:12:53+00:00Added an answer on June 17, 2026 at 1:12 pm

    as par your First point you need to your CellIdentifier replace with

      NSString *CellIdentifier =[NSString stringWithFormat:@"%d",indexPath.row];
    

    and

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    

    and second point Error says you have set cell.textLabel.text from placesArray that have no any Data or key like name at any index your Array is Nil that’s why your app Getting Crash while scrolling

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I've tracked down a weird MySQL problem to the two different ways I was
I know there's a lot of other questions out there that deal with this
I have a view passing on information from a database: def serve_article(request, id): served_article

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.