Greg’s Online CS 193P Resources

April 29, 2009

Tutorial for PushPop Demo (Pres1 Assignment) Added

Filed under: cs 193p,iPhone — gregorykaiser @ 11:56 pm
Tags:

I thought the PushPop Demo in lecture #7 was great. I went through it and added details about using Xcode and Interface Builder. This Tutorial is aimed at someone still uncertain about how to use Xcode and IB together to complete a mutiview multinib application. It would be a good starting point for the Presence 1 assignment if you need it. You can download it by right clicking the link below and the choosing “Save Link As”.

pushandpop4Tutorial

Advertisements

4 Comments »

  1. […] […]

    Pingback by Stanford Uni Course CS193P - iPhone Dev SDK Forum — April 30, 2009 @ 5:31 pm | Reply

  2. Hello,

    I really appreciate your tutorial (MVC View Controller).
    It was great!

    I wonder if you have had any experience with trying
    to pass data from the ListViewController to the
    DetailViewController? I can’t figure out what the
    “You’ll want to expose some properties so that it knows
    what to display.” part of Presence 1 assignment on page 6
    means. I created the three variables in the Detail controller

    IBOutlet id image;
    IBOutlet id imageName;
    IBOutlet id imageStatus;

    but can’t figure out how to reference them?
    (or pass them from the ListViewController).

    Thanks,

    Doug

    Comment by Doug — May 1, 2009 @ 10:33 pm | Reply

  3. Doug,

    I will work on another Tutorial over the weekend. I sort of took the quick path here of just passing the tag from the button pressed on the List screen to the Detail screen and then using the tag to update the values dynamically in the Detail view. You could extend this to all properties of the person.

    **1. In the DetailView.h I added the tag variable declaration and property statement and added tag to a new -intWithNibName declaration (You will see 3 lines marked //P2d)

    @interface SecondViewController : UIViewController {

    IBOutlet UIImageView *imageview; //P2i
    int tag; //P2d
    IBOutlet UILabel *label; //P2t

    }

    @property (nonatomic, retain) IBOutlet UIImageView *imageview; //P2i
    @property int tag; //P2d
    – initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil tag:(int)tagval; //P2d
    @end

    **2. I then went in the DetailView.m added @synthesize tag, Changed the method to add the Tag parameter and set it, and used it where needed. You should find these lines again with //P2d comments.

    @implementation SecondViewController

    @synthesize imageview; //P2i
    @synthesize tag; //P2d

    // The designated initializer. Override to perform setup that is required before the view is loaded.
    – (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil tag:(int)tagval { //P2d
    NSLog(@”Entering SecondViewController -initWithNibName.”); //P2
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
    // Custom initialization
    self.title = @”Second”; //7
    self.tag = tagval; //P2d
    //UIImage *img = [UIImage imageNamed:@”EvanDfa.png”]; //P2i
    //imageview.image = img; //P2i
    }
    return self;
    }

    // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
    – (void)viewDidLoad { //P2
    NSLog(@”In SecondViewController -viewDidLoad tag:%d “, self.tag); //P2d
    if (self.tag == 1) { //P2d only change Evan’s Data
    UIImage *img = [UIImage imageNamed:@”EvanDfa.png”]; //P2i
    imageview.image = img; //P2i
    label.text = @”Evan Teacher”; //P2t – Can Use this same idea for Status Field
    NSLog(@”In SecondViewController -viewDidLoad:Evan’s Detail Data Setup when Tag=1.”);
    } //P2d
    [super viewDidLoad];
    }

    ** 3. Finally, I had to change the call in the ListView which creates the Detail view to add Tag to it

    //P2d next line
    SecondViewController *viewController = [[SecondViewController alloc] initWithNibName:@”SecondView” bundle:nil tag:(int)button.tag];

    I hope this answers you question. If not write again.

    Greg

    Comment by gregorykaiser — May 1, 2009 @ 10:57 pm | Reply

  4. Greg,

    Many kind thanks to you again!
    That was exactly the information
    I needed.

    Cheers,

    Doug

    Comment by Doug — May 2, 2009 @ 12:10 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: