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 6611981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:02:28+00:00 2026-05-25T20:02:28+00:00

I’m currently working on an iPhone app that’s doing some strange things with a

  • 0

I’m currently working on an iPhone app that’s doing some strange things with a UIScrollView inside a UITableView. This is my first foray into iPhone dev, so I’m sure it’s something silly I’m missing.

In each UITableViewCell I am putting in a basic UITableViewCell. In that UITableViewCell is a Label and a UIScrollView.

The label and scrollview is setup and working properly, but when it first displays it is offset about 30 pixels down on the y axis than it should be, or is positioned by the XIB/NIB. I am not moving it around manually. The label shows up in the right spot. at 0,0. The UIScrollView should be showing up at 0,22 but is showing up closer to 0,40.

When I swipe to scroll the containing UITableView, then all the UIScrollViews will show up in the right spot assuming that when the UITableView scrolled that UITableViewCell went offscreen.

Here is the code for the UITableView.cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

  static NSString *CellIdentifier = @"GalleryRowCell";
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  if (cell == nil) cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
  [cell.layer setMasksToBounds:TRUE];
  [cell.layer setCornerRadius:10.0];


  Contagion *c = (Contagion *)[self.dataSet objectAtIndex:indexPath.row];
  GalleryRowViewController *subView = [[GalleryRowViewController alloc] initWithContagion:c];
  [cell.contentView addSubview:subView.view];
  subView.contagionName.text = c.name;
  subView.contagion = c;
  return cell;
}

Here is the code for my GalleryRowViewController.viewDidLoad

- (void)viewDidLoad {

[super viewDidLoad];

self.imageScroll.delegate = self;

[self.imageScroll setBackgroundColor:[UIColor blackColor]];
[self.imageScroll setCanCancelContentTouches:NO];

self.imageScroll.indicatorStyle = UIScrollViewIndicatorStyleWhite;
self.imageScroll.clipsToBounds = NO;
self.imageScroll.scrollEnabled = YES;
self.imageScroll.pagingEnabled = NO;

NSInteger x = 0;
CGFloat xPos = 0;
for (x=0;x<=10;x++) {
  UIImage *image = [UIImage imageNamed:@"57-icon.png"];
  UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
  [imageView setBackgroundColor:[UIColor yellowColor]];

  CGRect rect = imageView.frame;
  rect.size.height = 70;
  rect.size.width = image.size.width;
  rect.origin.x = xPos;
  rect.origin.y = 5;

  imageView.frame = rect;

  [self.imageScroll addSubview:imageView];
  xPos += imageView.frame.size.width+5;
}

[self.imageScroll setContentSize:CGSizeMake(xPos, [self.imageScroll bounds].size.height)];

}

— EDIT FOR IMAGES —

After App Loads: http://img809.imageshack.us/img809/4576/screenshot20110927at427.png

After Scrolling the rows offscreen and back: http://img690.imageshack.us/img690/9461/screenshot20110927at428.png

  • 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-25T20:02:29+00:00Added an answer on May 25, 2026 at 8:02 pm

    Well, as my previous response was at too low a level, let me take another shot at it.

    First, I just noticed the core problem that you’re using a viewcontroller for each cell. To quote Apple, ” “A single view controller typically manages the views associated with a single screen’s worth of content.” That would also get rid of your XIB (just manually configuring your scrollview), which I bet will get rid of your problem.

    To proceed, your main choice is whether to create a ContagionTableViewCell class or not as suggested by Scott.

    If so, following the Elements example, create a subclass of UITableViewCell ContagionTableViewCell with properties of a scrollView, a labelview and a contagion. Like they use a custom setter for the element, use one for the contagion, so that whenever it is assigned, it also updates the cells label (and associated pictures).

    Move your imageScroll code from GalleryRowViewController.viewDidLoad into the ContagionTableViewCell init code. Put the image code into a new routine, which will be called from the contagion setter.

    If NOT, then move the GalleryRowView Controller code into your UITableView. I suggest you take a look at cellForRowAtIndexPath in Apple’s tableViewSuite, the fourth example on subviews. In particular, it shows this pattern of separating the creation of a cell (when you need a brand new one) vs configuring the cell (when reusing it). As you have 10 imageViews inside your scrollView, you’ll have to decide whether to delete all those (and/or the scrollview), or just reach inside and update their images when a cell is reused.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
We're building an app, our first using Rails 3, and we're having to build
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,

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.