Session #3, Assignment #3

11 views
Skip to first unread message

Radamanthus Batnag

unread,
Feb 22, 2010, 8:14:55 PM2/22/10
to cocoahea...@googlegroups.com
How's everyone doing?

For those who were in the last meetup - how's your progress on assignment #3?
Can we finish it by this Thursday?

Me, I'm almost done. I just have to work on the persistence part (requirement #8). I can make it by Thursday, but I will not be able to work on the extra credits items. If we do the meetup next week I can work on the extra credits.

For those catching up, have you done Assignment 2? Any problems so far?

rad

paul_sns

unread,
Feb 22, 2010, 9:21:22 PM2/22/10
to cocoaheads-manila
The problem I had was the polygon view was not updating while the logs
show that the polygon already has the correct number of sides. Turns
out I instantiated another polygon object from within my code when
there's already another instance created by Interface builder when I
wired them up.

I also had a hard time formatting the code snippet from the assignment
PDF for determining the points in the polygon, so I'm including that
method here in case you need to copy and paste to your code (and do
not want to waste your time fixing the syntax).

+ (NSArray *)pointsForPolygonInRect:(CGRect)rect numberOfSides:
(int)numberOfSides {
CGPoint center = CGPointMake(rect.size.width / 2.0,
rect.size.height / 2.0);
float radius = 0.9 * center.x;
NSMutableArray *result = [NSMutableArray array];
float angle = ( 2.0 * M_PI ) / numberOfSides;
float exteriorAngle = M_PI - angle;
float rotationDelta = angle - ( 0.5 * exteriorAngle);
for ( int currentAngle = 0; currentAngle < numberOfSides ;
currentAngle++) {
float newAngle = (angle * currentAngle) - rotationDelta;
float curX = cos(newAngle) * radius;
float curY = sin(newAngle) * radius;
[result addObject:[NSValue
valueWithCGPoint:CGPointMake( center.x + curX, center.y + curY)]];
}
return result;
}

Might not be available this coming Thursday (as another group from our
church might start meeting regularly on this day) but I'll try to free
up my other Thursdays so I can catch up with the group.

Thanks,
Paul

crigor

unread,
Feb 24, 2010, 9:42:18 AM2/24/10
to cocoaheads-manila
I haven't started yet with assignment #3. How are the others doing?

On Feb 23, 9:14 am, Radamanthus Batnag <r...@batnag.org> wrote:

Eumir Gaspar

unread,
Feb 28, 2010, 2:50:01 AM2/28/10
to cocoahea...@googlegroups.com
Im trying to do #3 right now but im kinda at a loss on where to start. Where do i connect the UIView object? Do i make a new controller for that or do I add a new method to the same controller for the labels and inc/dev buttons?
--
Eumir Gaspar
Web Developer
http://admoolabs.com

Eumir Gaspar

unread,
Feb 28, 2010, 2:50:19 AM2/28/10
to cocoahea...@googlegroups.com
I meant increase/decrease buttons, sorry.

paul_sns

unread,
Feb 28, 2010, 8:00:25 AM2/28/10
to cocoaheads-manila
The approach I did was to create a Controller object (subclass of
NSObject) and PolygonView (subclass of UIView).

The Controller object has the connections to the UILabels, UIButtons,
PolygonView and PolygonShape wired through Interface Builder. (no
alloc/inits inside my classes)

My MainWindow.xib is structured similar to below:

MainWindow.xib
- FO
- FR
- App Delegate
- Window
- Labels
- Buttons
- Poly View
- Label
- Controller
- Poly Shape

My Controller calls appropriate method in view when the inc/dec
buttons are clicked. This means the Controller contains the IBActions
for the buttons.

ApplicationDelegate also holds reference to Controller so I can set/
save the number of sides during startup/shutdown.

Hope I provided enough to get you started without giving away too much
info. :)

If there are better alternatives, please feel free to send in your
suggestions. ;)

Care to share high level overview of your solution Rad?

Cheers,
Paul

On Feb 28, 3:50 pm, Eumir Gaspar <imacaterpil...@gmail.com> wrote:
> I meant increase/decrease buttons, sorry.
>

Radamanthus Batnag

unread,
Mar 1, 2010, 6:51:24 PM3/1/10
to cocoahea...@googlegroups.com
My solution is almost exactly like Paul's.

One difference is I did not make my Controller an ApplicationDelegate but instead used NSNotificationCenter. I'm still studying when it makes sense to use delegates and when it is better to use notifications.

We're all set for session #3 this Thursday, right?
Any suggestions for a venue? How about Coffee Bean in Emerald Ave., Ortigas?

r

Hartsord

unread,
Mar 2, 2010, 10:42:54 AM3/2/10
to cocoaheads-manila
Hello everybody, I'm Cliff, and I'm also studying the Stanford
classes.

I'm currently having trouble with my UIView subclass; specifically, I
added a property to the subclass to hold the number of sides of the
polygon, but it seems to lose the value by the time it gets to the
drawrect method.

----------------------------------------

// DrawPoly.m

#import "DrawPoly.h"

@implementation DrawPoly {
int polySides;
}

@synthesize polySides;

-(id)init {
return [self initWithSides:6];
}

-(id)initWithSides:(int)newSides {
self = [super init];
self.polySides = newSides;
[self setNeedsDisplay];
return self;
}
------------------------------------------------

So when I initialize it, the polySides property has the number of
sides, but by the time I reach the drawRect method:

--------------------------------------------

-(void)drawRect:(CGRect)rect {
//get the points
NSArray *polyArray = [DrawPoly pointsForPolygonInRect:rect
numberOfSides:self.polySides]; // this doesn't work, polysides is 0
// NSArray *polyArray = [DrawPoly pointsForPolygonInRect:rect
numberOfSides:6]; // this works
NSValue *value;
CGPoint point;
...
--------------------------------------------

the polySides property is now 0, as verified in the debugger. What
gives? Any idea?

Radamanthus Batnag

unread,
Mar 2, 2010, 11:36:18 AM3/2/10
to cocoahea...@googlegroups.com
Hi Cliff,

Welcome to the group.

I encountered something similar in my solution. I don't understand enough to be able to explain why, but I can share my observations.

First off, my code is a bit different - my custom UIView (I named it PolygonView) has a PolygonShape IBOutlet, and that's where I get the number of sides to render. 

What I observed in my code was, [polygon init] wasn't being called. So, to initialize my polygon, I added these in my controller's awakeFromNib:

[polygon setMinimumNumberOfSides:minimumNumberOfSides];
[polygon setMaximumNumberOfSides:maximumNumberOfSides];
[polygon setNumberOfSides:numberOfSides];

Prior to the call, I initialized the variables minimumNumberOfSides, maximumNumberOfSides and numberOfSides from NSUserDefaults.

Hope this helps,
rad

paul_sns

unread,
Mar 2, 2010, 7:04:09 PM3/2/10
to cocoaheads-manila
Hi Cliff!

Welcome to the Cocoa Heads mailing list / CS193p study group.

Can you check if you have multiple instances of the DrawPoly class
running in your application? That was originally my problem. I already
had it wired in IB then I also created another instance using alloc/
init. I saw my polygon updating in the logs, but not in the view. All
the problems went away when I removed all alloc/inits in my code and
moved the creation to IB.

If you're interested, you can send me your copy and I'll try to run it
on debug mode from my machine.

Cheers,
Paul

paul_sns

unread,
Mar 2, 2010, 7:08:25 PM3/2/10
to cocoaheads-manila
I think Rad might be on to something, instead of init, can you try
using - (id)initWithFrame:(CGRect)aRect?

Hartsord

unread,
Mar 3, 2010, 4:42:46 AM3/3/10
to cocoaheads-manila
Hmmm, there might be something there, but this thing is getting a bit
frustrating, so I think I'll start clean.

So what I have that I can reuse:
- I have a PolyShape class, which I will use as the model in my
VMC.
- I have the guts of my DrawPoly class, which is capable of drawing
the poly (calling directly), but seems to forget how many sides the
poly is supposed to have (my plan is to have the controller get the
sides from the PolyShape class, then set it in the DrawPoly class,
then have the DrawPoly class draw itself.)

So I have those, but where exactly should I actually allocate, init
and add it to the view controller's view?

paul_sns

unread,
Mar 3, 2010, 7:02:31 AM3/3/10
to cocoaheads-manila
Since this assignment was done before the lecture on ViewControllers,
the Controller I used was not a subclass of UIVIewController but
simply of NSObject and my PolyView was added to MainWindow through
interface builder.

Because everything is wired in IB, the alloc/init call to your view
will be done when MainWindow.xib is loaded (calls awakeFromNib).

Hope that helps! Please feel free to post any other follow up
questions you may have.

Cheers,
Paul

Eumir Gaspar

unread,
Mar 3, 2010, 7:10:51 AM3/3/10
to cocoahea...@googlegroups.com
As for the meetup, is everyone game for tomorrow? 

As Rad said:
Any suggestions for a venue? How about Coffee Bean in Emerald Ave., Ortigas?  <-- im okay with this but i really still dont have a clue(i will try to work on it again later based on the discussion here), if ever, maybe one of you can discuss this to the others who haven't completed as well?

Hartsord

unread,
Mar 3, 2010, 8:30:56 AM3/3/10
to cocoaheads-manila
You can do it in IB? How do you override the drawrect method to draw
the polygon? If that can be done, things would be so much easier, at
least for now.

I thought you had to make a UIView subclass and wire it up from
scratch to get this to work.

Hartsord

unread,
Mar 3, 2010, 8:51:15 AM3/3/10
to cocoaheads-manila
You can do it in IB? How do you override the drawrect method to draw
the polygon? If that can be done, things would be so much easier, at
least for now.

I thought you had to make a UIView subclass and wire it up from
scratch to get this to work.

On Mar 3, 8:02 pm, paul_sns <plab.s...@gmail.com> wrote:

Hartsord

unread,
Mar 3, 2010, 9:05:56 AM3/3/10
to cocoaheads-manila
You can do it in IB? How do you override the drawrect method to draw
the polygon? If that can be done, things would be so much easier, at
least for now.

I thought you had to make a UIView subclass and wire it up from
scratch to get this to work.

On Mar 3, 8:02 pm, paul_sns <plab.s...@gmail.com> wrote:

paul_sns

unread,
Mar 3, 2010, 9:17:24 AM3/3/10
to cocoaheads-manila
Try to drag a UIView to MainWindow in IB then change the type to your
UIVIew subclass (in this case your DrawPoly class which overrides
drawRect). I'm not sure where exactly but I think this approach was
mentioned in one of the assignment walkthroughs.

Paul

Radamanthus Batnag

unread,
Mar 3, 2010, 11:37:07 AM3/3/10
to cocoahea...@googlegroups.com
I'm game for tomorrow, 730pm onward.
Anyone else coming?

paul_sns

unread,
Mar 3, 2010, 10:51:48 PM3/3/10
to cocoaheads-manila
Sorry for the late reply, I just found out that I'm also free for
tonight. But do we have enough numbers? It might be a good idea to
wait for those who are still working on the assignment so we're all on
the same page. What do you guys think?

Cheers,
Paul

On Mar 4, 12:37 am, Radamanthus Batnag <r...@batnag.org> wrote:
> I'm game for tomorrow, 730pm onward.
> Anyone else coming?
>
> On Mar 3, 2010, at 8:10 PM, Eumir Gaspar wrote:
>
> > As for the meetup, is everyone game for tomorrow?
>
> > As Rad said:
> > Any suggestions for a venue? How about Coffee Bean in Emerald Ave., Ortigas?  <-- im okay with this but i really still dont have a clue(i will try to work on it again later based on the discussion here), if ever, maybe one of you can discuss this to the others who haven't completed as well?
>

Christopher Rigor

unread,
Mar 3, 2010, 11:14:17 PM3/3/10
to cocoahea...@googlegroups.com
I can attend, but I'll start doing the assignment there :)

Radamanthus Batnag

unread,
Mar 4, 2010, 4:39:35 AM3/4/10
to cocoahea...@googlegroups.com
Do we do the meetup? I'm ok either way, but I'm out of town next week.

Radamanthus Batnag

unread,
Mar 4, 2010, 4:51:49 AM3/4/10
to cocoahea...@googlegroups.com
Let's do the meetup at the Devex.com office:
1901 Orient Square, Emerald Ave.
730pm onward.

Those of us from Devex will be here anyway.
If you haven't done the assignment, you can do it during the meetup,
or just participate in the discussion of the solution.

I probably sound stubborn in pushing for the meetup despite the lack
of numbers. I am. We're at assignment 3, week 3, lecture 6, and around
the time I stopped my CS193p self-study last year. I don't want to
repeat again :p

Eumir Gaspar

unread,
Mar 4, 2010, 5:08:06 AM3/4/10
to cocoahea...@googlegroups.com
i almost stopped too because i got stuck din hahaha

paul_sns

unread,
Mar 4, 2010, 5:09:41 AM3/4/10
to cocoaheads-manila
That's perfectly fine Rad. I know where you're coming from, I'm a
repeater of the Stanford class too! :)

The key difference is that I didn't work on any of the assignments
last year. I only started working on them this year because of peer
pressure, I mean motivation from the study group. ;) I also encourage
the others to work on the assignments, as this is the only way we can
learn. We can watch the videos all day long and not learn anything,
which is what happened to me with the first round of the Stanford
lectures.

I'd love to join tonight's session but I think it's already too late
to tell my significant other that I would be leaving the house in a
few minutes. We're both home based and we currently do not have house
help so it's really hard to go out with such a short notice,
especially with two kids fighting for attention. I hope you guys would
understand.

As always, please feel free to send notable discussions regarding the
meeting.

Rad, sorry di ako maka reply sa text mo. Di pa ako nakaka load since
the other day. :)

If you want, we can also exchange assignments through email so we can
compare notes. How does that sound?

Thanks,
Paul

On Mar 4, 5:51 pm, Radamanthus Batnag <radamant...@gmail.com> wrote:
> Let's do the meetup at the Devex.com office:
> 1901 Orient Square, Emerald Ave.
> 730pm onward.
>
> Those of us from Devex will be here anyway.
> If you haven't done the assignment, you can do it during the meetup,
> or just participate in the discussion of the solution.
>
> I probably sound stubborn in pushing for the meetup despite the lack
> of numbers. I am. We're at assignment 3, week 3, lecture 6, and around
> the time I stopped my CS193p self-study last year. I don't want to
> repeat again :p
>
> On Thu, Mar 4, 2010 at 5:39 PM, Radamanthus Batnag
>

> <radamant...@gmail.com> wrote:
> > Do we do the meetup? I'm ok either way, but I'm out of town next week.
>
> > On Thu, Mar 4, 2010 at 12:14 PM, Christopher Rigor <cri...@gmail.com> wrote:
> >> I can attend, but I'll start doing the assignment there :)
>

> ...
>
> read more »

Radamanthus Batnag

unread,
Mar 4, 2010, 11:10:07 AM3/4/10
to cocoahea...@googlegroups.com
Paul,

No worries, I understand your situation. I'm lucky to have househelp now, but I've been in your situation, too. Tough.

During last night's sessions, we discussed assignment #3. Eumir worked on it, but got stuck on how to connect the PolygonView to the controller and the PolygonShape model. Your email earlier this week more or less described my similar solution. It was just easier to discuss concepts and code in a meetup.

For the next two weeks, we'll do lectures 7 and 8, and assignment 4 (Paparazzi 1).

Also, it looks like a significant number of people on the list are falling behind and are still not done with the earlier assignments. If there's enough interest, maybe we can do a short session on assignments 1B and 2A. Lurkers, interested?

Regards,
rad

Hartsord

unread,
Mar 10, 2010, 7:18:08 AM3/10/10
to cocoaheads-manila
Ugh. I am so slow. This helped me to figure out my issues.
1) I was trying to do the view programmatically. More trouble than
it's worth for me at this stage of my learning.
2) I was double declaring my ivars, once in the header, once in the .m
file.

This post in the Apple developer forum also helped me realize what was
going wrong: http://discussions.apple.com/message.jspa?messageID=11167725

Radamanthus Batnag

unread,
Jul 20, 2010, 11:56:45 AM7/20/10
to cocoahea...@googlegroups.com
Hi folks,

I'm posting this for a friend. The company will be building iPhone apps that talk to an RoR backend.

Work will be home-based, San Francisco time.

rad

---

Iphone App Developer for a Telephony Startup Firm

We are seeking a top-caliber, enthusiastic lead iPhone developer to join our promising firm as a core member of an experienced, leadership team. The role will require design initiative and team collaboration, as well as extensive, efficient coding. The iPhone developer will report to and collaborate with the CTO to deliver a novel platform from the ground-up.

REQUIREMENTS:
- Bachelor's degree in Computer Science or equivalent
- Expert-level proficiency of object-oriented programming in Objective-C and software design patterns
- Advanced knowledge of the iPhone SDK platform frameworks
- Experience setting up and maintaining an iPhone application project, including setting up ad-hoc distribution of builds

DESIRED:
- Experience with Core Audio and the new Media Player framework in iPhone SDK 3.0
- Experience with Internet communication (i.e. Core Foundation NSURL APIs) and parsing data (XML, JSON, etc)
- Familiarity with digital media and streaming
- Familiarity with Ruby on Rails

Compensation will be commensurate with experience and highly competitive skills.Please email resume at in...@wideumbrella.com


Reply all
Reply to author
Forward
0 new messages