Graphics Programs Reference
In-Depth Information
A custom button doesn't do any drawing by default (unlike, for example, a rounded rect-
angle button that draws a white pill with a blue outline). This means it starts out as a trans-
parent button with nothing on it. If we wanted to, we could use an image or subclass
UIButton
and override
drawRect:
to give this button a totally custom look. But in
our case, we just want a transparent button, so we're done.
At this point, though, we run into a problem: the action message of the button will be sent
to the
HomepwnerItemCell
. But
HomepwnerItemCell
is not a controller and
doesn't have access to any of the image data necessary to get the full-size image. In fact, it
doesn't even have access to the
BNRItem
whose thumbnail it is displaying.
We could consider letting
HomepwnerItemCell
keep a pointer to the
BNRItem
it dis-
plays. But, table view cells are view objects, and they shouldn't manage model objects or
be able to present additional interfaces (like the
UIPopoverController
).
So our plan, instead, is to give
HomepwnerItemCell
a pointer to
ItemsViewCon-
troller
. (
ItemsViewController
is the controller object that manages the
UIT-
ableView
that
HomepwnerItemCell
s belong to, so it is also the controller of every
HomepwnerItemCell
.) Then, when the
HomepwnerItemCell
receives the action
message from the button, it will send a new message to the
ItemsViewController
so that the controller can fetch the image and present it in the
UIPopoverControl-
ler
.
Adding pointers to cell subclass
Now we need to give
HomepwnerItemCell
that pointer to the controller as well as a
pointer to the table view that the cell belongs to. In
HomepwnerItemCell.h
, add the
following two properties.
@property (weak, nonatomic) id controller;
@property (weak, nonatomic) UITableView *tableView;
These properties are weak because the
HomepwnerItemCell
is owned by its
tableView
already. Its
tableView
is owned by its
controller
. Thus, making