Objectively Speaking 2: A Crash Course in Objective-C for iOS 6

Discussion of the official tutorials published on raywenderlich.com. Please only discuss the official tutorials here - for general questions, use the General Discussion forum instead.

Objectively Speaking 2: A Crash Course in Objective-C for iOS 6

Postby rwenderlich » Wed May 01, 2013 11:00 am

This is the official thread to discuss the following blog post: Objectively Speaking 2: A Crash Course in Objective-C for iOS 6
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2237
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 372 times

Re: Objectively Speaking 2: A Crash Course in Objective-C fo

Postby simon111 » Thu May 02, 2013 12:29 pm

This tutorial is great, in particular, the property list part. I didn't use property list before. Now, I know to manage it in iOS.
simon111
n00b
 
Posts: 2
Joined: Tue Oct 16, 2012 10:46 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Objectively Speaking 2: A Crash Course in Objective-C fo

Postby triggerx » Fri May 10, 2013 1:26 pm

Hi, great tutorials. I'm new to iOS programming (most proficient in web programming... PHP fwiw). I took part 1, and was dead simple... part 2 seemed to be going along fine, but when I got to the "Build and run your app, and now you should have a fully functional quiz!" part.... it didn't act like it should. I could answer all the questions, and it would show me correct/incorrect scores. But, after all the questions, it went back to question #1 and cleared my "scores." Basically, I never got a score percentage, or a "Try Again" button. So, I deduced that where "(void)nextQuizItem" was added to QuoteQuizViewController.m, it wasn't ever actually getting to the [self quizDone] part. I'm trying to wrap my brain around why not, but basically... it's never executing the "else" that would lead to quizDone.

For example, there are 16 quiz questions... and say you fall into nextQuizItem on the last item.. you'll have: self.quiz.quizCount = 16 and self.quizIndex = 15, you'll then hit the "else" up top, and will set your quizIndex back to 0. Then in the next part self.quiz.quizCount >= self.quizIndex +1 will always be true... so the else, that takes you to quizDone won't ever trigger.

I've double checked my code, and appears to be the same as the tutorial... but you never know. Am I missing something, or is there a typo somewhere?

Thanks!
triggerx
n00b
 
Posts: 1
Joined: Fri May 10, 2013 12:59 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Objectively Speaking 2: A Crash Course in Objective-C fo

Postby noloman » Tue May 14, 2013 2:36 pm

Hey there!

First of all, congratulations for the tutorial, it's a very good one!

I'm trying to set up the part of the delegate but I'm getting the following error when pressing the TIP button:

Code: Select all
QuoteQuiz[82224:c07] -[QuizTipViewController _setViewDelegate:]: unrecognized selector sent to instance 0x68c9dc0


Am I missing something?

Thanks a lot!
noloman
n00b
 
Posts: 2
Joined: Mon Jan 28, 2013 10:19 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Objectively Speaking 2: A Crash Course in Objective-C fo

Postby rcasey » Tue May 14, 2013 3:45 pm

@noloman

Check the prepareForSegue method in QuoteQuizViewController.m.

That is where the delegate should be getting set.
rcasey
Team Member
Forum Subject Matter Expert
 
Posts: 1245
Joined: Fri Jul 01, 2011 6:50 pm
Has thanked: 2 times
Been thanked: 267 times

Re: Objectively Speaking 2: A Crash Course in Objective-C fo

Postby noloman » Tue May 14, 2013 4:13 pm

rcasey wrote:@noloman

Check the prepareForSegue method in QuoteQuizViewController.m.

That is where the delegate should be getting set.


I changed the type of the view (instead of being UIView) when what I wanted was to change the type of the view controller :oops:
Last edited by noloman on Wed May 15, 2013 5:32 am, edited 1 time in total.
noloman
n00b
 
Posts: 2
Joined: Mon Jan 28, 2013 10:19 pm
Has thanked: 1 time
Been thanked: 0 time

Re: Objectively Speaking 2: A Crash Course in Objective-C fo

Postby rawk » Wed May 15, 2013 2:04 am

It seems that tipCount is not incremented anywhere in the tutorial so the 3 tip limit is not enforced. I added the the following line at the bottom of the if statement in the prepareForSegue method in QuoteQuizViewController.m:

Code: Select all
self.quiz.tipCount++;


It seemed to do the trick. Would that be the proper place to increment this variable?
rawk
n00b
 
Posts: 1
Joined: Wed May 15, 2013 2:00 am
Has thanked: 0 time
Been thanked: 0 time

Re: Objectively Speaking 2: A Crash Course in Objective-C fo

Postby swinz » Thu May 16, 2013 1:21 pm

Hi Linda,

love the crash course articles. I've been planning to build an app for my son and you've armed me with all I need.

Thanks,
Ian
swinz
n00b
 
Posts: 1
Joined: Thu May 16, 2013 1:18 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Objectively Speaking 2: A Crash Course in Objective-C fo

Postby TavOs » Wed May 22, 2013 4:14 am

Well, I also noticed the undesirable behaviour of the App not showing the score label (and changing the text on the button) when you finish the quiz.

I think for those who also found this issue and fixed it, this was a good exercise, because it made us troubleshoot and analyse the code.

This was the way I fix it (I know it is not the best way, but it worked for me and there wasn't a major change in the code)

I hope this can be helpful.

Code: Select all
- (void)nextQuizItem
{
    BOOL endGame = NO;
   
    if (self.quizIndex == 999) {            //Aqui comienza desde el principio
        self.quizIndex = 0;
        self.statusLabel.text = @"";
    } else if ((self.quiz.quizCount-1) > self.quizIndex) {      //Aqui avanza de pregunta
        self.quizIndex++;
    } else {                        //Aqui acaba
        self.quizIndex = 0;
        self.statusLabel.text = @"";
       endGame = YES;
    }
   
    if ((self.quiz.quizCount >= self.quizIndex + 1) && (!endGame)) {
        [self.quiz nextQuestion:self.quizIndex];
        self.questionLabel.text = self.quiz.quote;
        self.answer1Label.text = self.quiz.ans1;
        self.answer2Label.text = self.quiz.ans2;
        self.answer3Label.text = self.quiz.ans3;
    } else {
        self.quizIndex = 0;
        [self quizDone];
    }
   
    // reset fields for next question
    self.answer1Label.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
    self.answer2Label.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
    self.answer3Label.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
   
    self.answer1Button.hidden = NO;
    self.answer2Button.hidden = NO;
    self.answer3Button.hidden = NO;
}
TavOs
n00b
 
Posts: 1
Joined: Wed May 22, 2013 4:03 am
Has thanked: 0 time
Been thanked: 0 time

Re: Objectively Speaking 2: A Crash Course in Objective-C fo

Postby takoyaki » Wed May 22, 2013 9:34 pm

Here are the issues I found with the tutorial code as is:
- never gets to quizDone
- startButton is always displayed
- score calculation on quizDone not correct
- tip count not incremented

And here's how I fixed it.

- never gets to quizDone => fixed if statement comparison

- startButton is always displayed => moved initialization and added hide=YES when initializing for next question

- score calculation on quizDone not correct => changed to decimal x/y indication (I guess you don't need the div by 0 check in this case)

- tip count not incremented => incremented when preparing segue and hid infoButton so multiple increments won't happen


Code: Select all
- (void) quizDone
{
    if (self.quiz.correctCount) {
        self.statusLabel.text = [NSString stringWithFormat:@"Quiz Done - Score %d/%d",self.quiz.correctCount,self.quiz.quizCount];
    } else {
        self.statusLabel.text = @"Quiz Done - Score: 0%";
    }
    [self.startButton setTitle:@"Try Again" forState:UIControlStateNormal];
    self.quizIndex=999;
    self.startButton.hidden=NO;
}

- (void) nextQuizItem
{
    if (self.quizIndex==999){
        self.quizIndex=0;
        self.statusLabel.text=@"";
    } else if ((self.quiz.quizCount)>self.quizIndex) { //tako - don't need the -1
        self.quizIndex++;
    } else {
        self.quizIndex=0;
        self.statusLabel.text=@"";
    }
   
    if (self.quiz.quizCount>=self.quizIndex+1) {
        [self.quiz nextQuestion:self.quizIndex];
        self.questionLabel.text=self.quiz.quote;
        self.answer1Label.text=self.quiz.ans1;
        self.answer2Label.text=self.quiz.ans2;
        self.answer3Label.text=self.quiz.ans3;

        //reset fields for next quetion //tako - moved initialization only when there's next question
        self.answer1Label.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
        self.answer2Label.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
        self.answer3Label.backgroundColor = [UIColor colorWithRed:51/255.0 green:133/255.0 blue:238/255.0 alpha:1.0];
       
        self.answer1Button.hidden=NO;
        self.answer2Button.hidden=NO;
        self.answer3Button.hidden=NO;
        self.startButton.hidden=YES; //tako - hide start button
    } else {
        self.quizIndex=0;
        [self quizDone];
    }
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"TipModal"]) {
        QuizTipViewController *detailViewController = (QuizTipViewController *) segue.destinationViewController;
        detailViewController.delegate=self;
        detailViewController.tipText=self.quiz.tip;
        self.quiz.tipCount++; //tako - incr tip count
       
        self.infoButton.hidden=YES; //tako - hide tip button once displayed
    }
}
 }
takoyaki
n00b
 
Posts: 4
Joined: Wed May 22, 2013 9:29 pm
Has thanked: 0 time
Been thanked: 0 time

Next

Return to Official Tutorials

Who is online

Users browsing this forum: Google [Bot] and 5 guests