-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
static NSString *QuoteCellIdentifier = @"QuoteCellIdentifier";
QuoteCell *cell = (QuoteCell*)[tableView dequeueReusableCellWithIdentifier:QuoteCellIdentifier];
if (!cell) {
UINib *quoteCellNib = [UINib nibWithNibName:@"QuoteCell" bundle:nil];
[quoteCellNib instantiateWithOwner:self options:nil];
cell = self.quoteCell;
self.quoteCell = nil;
if ([MFMailComposeViewController canSendMail]) {
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
[cell addGestureRecognizer:longPressRecognizer];
}
else {
NSLog(@"Mail not available");
}
}
Play *play = (Play *)[[self.sectionInfoArray objectAtIndex:indexPath.section] play];
cell.quotation = [play.quotations objectAtIndex:indexPath.row];
return cell;
}
#pragma mark Handling long presses
-(void)handleLongPress:(UILongPressGestureRecognizer*)longPressRecognizer {
/*
For the long press, the only state of interest is Began.
When the long press is detected, find the index path of the row (if there is one) at press location.
If there is a row at the location, create a suitable menu controller and display it.
*/
if (longPressRecognizer.state == UIGestureRecognizerStateBegan) {
NSIndexPath *pressedIndexPath = [self.tableView indexPathForRowAtPoint:[longPressRecognizer locationInView:self.tableView]];
if (pressedIndexPath && (pressedIndexPath.row != NSNotFound) && (pressedIndexPath.section != NSNotFound)) {
[self becomeFirstResponder];
UIMenuController *menuController = [UIMenuController sharedMenuController];
EmailMenuItem *menuItem = [[EmailMenuItem alloc] initWithTitle:@"Email" action:@selector(emailMenuButtonPressed:)];
menuItem.indexPath = pressedIndexPath;
menuController.menuItems = [NSArray arrayWithObject:menuItem];
[menuController setTargetRect:[self.tableView rectForRowAtIndexPath:pressedIndexPath] inView:self.tableView];
[menuController setMenuVisible:YES animated:YES];
}
}
}
-(IBAction)deleteButtonHandle:(id)sender {
UITableViewCell *cell = (UITableViewCell *)[[sender superview] superview];
NSIndexPath *index = [self.tableView indexPathForCell:cell];
int row = index.row;
int section = index.section;