Database Reference
In-Depth Information
Let's now move over to the EntryCollectionViewCell.m file and make some more modifications.
The first thing we want to do is create a private interface. We will add four properties inside it for
our UILabel , UIImageView , EntryCollectionViewDelegate , and our NSString . We add IBOutlet
commands to the label and image view so we can connect them in interface builder. The private
interface should look like this:
@interface EntryCollectionViewCell()
@property (weak) IBOutlet UIImageView *imgPhoto;
@property (weak) IBOutlet UILabel *lblDisplayName;
@property (assign) id<EntryCollectionViewCellDelegate> delegate;
@property (assign) NSString *entry;
@end
Next we can remove all the boilerplate code inside the implementation. You should be left with only
the @implementation line and the @end line.
We want to set up a UILongPressGesture Recognizer for this cell. Because our cell is instantiated
from the storyboard, we will write the initWithCoder method and add our gesture recognizer
addition there.
-(id)initWithCoder:(NSCoder *)aDecoder {
if((self = [super initWithCoder:aDecoder])){
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(longPressed:)];
[self addGestureRecognizer:longPress];
}
return self;
}
In the initWithCoder method we created a long press gesture recognizer and added it to our self,
the view. In the creation of the recognizer we reference an action method longPressed :. Let's
write that method now.
-(void)longPressed:(UIGestureRecognizer *)gesture {
if(gesture.state == UIGestureRecognizerStateBegan){
[_delegate entryCollectionViewCell:self longPressedForEntry:_entry];
}
}
As you can see, this is a very simple pass through method. But, there is one caveat that I want to
point out. The first line of this method checks the state of the gesture. The reason we do this in this
instance is that the recognizer will actually fire this method twice. It is called when the gesture begins
and ends. Because we are only concerned with it when it begins, we check the state and only act
on it when it is UIGestureRecognizerStateBegan . Once we know the state has begun, we call our
delegate method on the registered delegate.
Now we need to add our configureCellForEntry:withDelegate implementation. In this method we
will simply take the incoming variables and assign them to our local variables as long as entry is not
nil. Then we will configure the image view and the label. Because we aren't handling an image right
now, we will use the ImgCellNoImage for the time being.
 
Search WWH ::




Custom Search