Best way to do this... (your opinion)

Discussion in 'iOS Development' started by studio:19, Jun 22, 2009.

  1. studio:19

    studio:19 New Member

    Joined:
    Jun 3, 2009
    Messages:
    3
    Likes Received:
    0
    I am working on something and I have a set of instructions, or more of a prequel story that would be read before the opening... blah blah blah...

    But basically what I am going to have about 50-60 sets of text all on a separate page, and have a top Tool Bar with two UIBarButtonItem, one saying "Next" and the other "Back"

    Now obviously I dont want to make 50 new .xib files, so what do you think the best way to do this would be?

    Thanks!
  2. bamhm182

    bamhm182 Member

    Joined:
    Mar 2, 2009
    Messages:
    544
    Likes Received:
    0
    Device:
    3G iPod touch
    Wow, you've got 60 pages for them to read through? :S

    Anyways, you could do it in 1 xib, than have different views for each page. You could than set up something like this:

    Code:
    - (IBAction)nextButtonPressed:(id)sender;
    {
    	[UIView beginAnimations:nil context:nil];
    	[UIView setAnimationDuration:1.0];
    	CGAffineTransform transform = CGAffineTransformMakeTranslation(-320, 0);
    	Page1View.transform = transform;
    	CGAffineTransform transform2 = CGAffineTransformMakeTranslation(-320, 0);
    	Page2View.transform = transform2;
    	[UIView commitAnimations];
    }
    
    - (IBAction)backButtonPressed:(id)sender;
    {
    	[UIView beginAnimations:nil context:nil];
    	[UIView setAnimationDuration:1.0];
    	CGAffineTransform transform = CGAffineTransformMakeTranslation(320, 0);
    	Page1View.transform = transform;
    	CGAffineTransform transform2 = CGAffineTransformMakeTranslation(320, 0);
    	Page2View.transform = transform2;
    	[UIView commitAnimations];
    }
    I'm sure there must be a better way to set the Page 1 and Page 2 views but I'm not sure how. This way would only work well if you had very few pages. To get this set right, you would have to make something to tell your app to check which page it is on, than set the next and previous pages accordingly. I'm not sure how you could do this, but perhaps someone else here will tell you.

    You could also put in a scroll view. Those are really easy to set up, you can just make it the right size in IB, than put something like:

    Code:
    - (void)viewDidLoad
    {
    scrollView.contentSize = CGSizeMake(width, height)
    }
    Hope this helps.
  3. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    Wow, to be honest, I don't know what kind of app you are going to make if you don't know how to sort this...

    Just make a UILabel and update the text whenever a button is pressed. Probably from an array or an NSDictionary, IDK.
  4. bamhm182

    bamhm182 Member

    Joined:
    Mar 2, 2009
    Messages:
    544
    Likes Received:
    0
    Device:
    3G iPod touch
    Oh yeah... I forgot you could do that. Pelaez's idea would work better.
  5. wearmaize

    wearmaize Active Member

    Joined:
    Feb 13, 2008
    Messages:
    2,442
    Likes Received:
    13
    Device:
    iPhone 4S (Black)
    You could set up a page number in a label and then have a whole bunch of if statements.

    So, if lable.text == 0 //load page 1.
    if lable.text == 1 //load page 2

    etc.
  6. Chicken

    Chicken Retired Moderator

    Joined:
    Feb 17, 2008
    Messages:
    2,494
    Likes Received:
    7
    Device:
    iPhone 5S
    If you were to do that , the switch case break method would be quicker.
  7. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    Hell no!
    Code:
    pageLabel.text = [NSString stringWithFormat:@"%d", pageNumber];
    [myTextViewController viewTextPage:pageNumber];
  8. Pelaez-1

    Pelaez-1 New Member

    Joined:
    May 5, 2008
    Messages:
    822
    Likes Received:
    0
    Device:
    iPhone
    Wow, you guys need to keep it simple.

    It's as simple as having an NSArray with the texts, a UILabel, and an integer which will be the page number.
    When a button is pressed, you add/substract 1 to the integer, and refresh the label text with [array objectAtIndex:i];
    You can even add effects like fading out the UILabel, changing the text, and fading it in, or something like that.
  9. bddckr

    bddckr Active Member

    Joined:
    Dec 2, 2007
    Messages:
    1,434
    Likes Received:
    18
    Device:
    iPhone 4 (Black)
    That's what I posted... in a different way

    Please Register or Log in to view images


    There are so many ways to do that stuff "dynamically" so don't think of any "static" solutions. That's what real programming makes interesting.

    Please Register or Log in to view images

Share This Page