playing with variables and text views

Discussion in 'iOS Programming' started by blueblaze4444, Dec 13, 2011.

  1. blueblaze4444 macrumors newbie

    Joined:
    Dec 3, 2011
    #1
    I'm a bit of a newb here. So given the code shown below, I have a UITextView called scheduleView which changes from day to day - I'm using the variable "day" which represents the day of the year (This is meant to display a school's daily rotation/schedule - which are all stored in strings which I didn't include below). But let's say that I wanted to scroll through this text view - as in, sliding/pulling the textview right or left to see schedules for the days to come or previous days. I'm guessing that somehow I would have to use an action which adds or subtracts 1 from "day" each time it is performed. My question is: what kind of action would I use to do this?

    Code:
    NSDate *today = [[NSDate alloc] init];
        NSCalendar *cal = [NSCalendar currentCalendar];
        NSUInteger day = [cal ordinalityOfUnit:NSDayCalendarUnit
                                        inUnit:NSYearCalendarUnit
                                       forDate:today];
        
        if (day == 341) {
            scheduleView.text = R2;
        }
        else if (day == 339){
            scheduleView.text = LS;
        }
        else if (day == 342) {
            scheduleView.text = B1;
        }
        else if (day == 343) {
            scheduleView.text = B2;
        }
        else if (day == 345) {
            scheduleView.text = R1;
        }
        else if (day == 346) {
            scheduleView.text = R2;
        }
        else if (day == 347) {
            scheduleView.text = R3;
        }
        else if (day == 348) {
            scheduleView.text = R1;
        }
        else if (day == 349) {
            scheduleView.text = MS;
        }
        
        else {
            scheduleView.text = @"No School Today!";
        }
        
    }
    
     
  2. jonnymo5 macrumors 6502

    Joined:
    Jan 21, 2008
    Location:
    Texas
    #2
    You might want to consider putting the schedules in different views and presenting them in something like a scroll view. You will have a much easier time detecting that the user scrolled and updating the content.

    Check out the UIScrollView docs, its delegate protocol and the PhotoScroller sample project.

    Should give you some ideas!
     

Share This Page