Static table view cells seem to have the same data and cell selected index?
Basically I need two things to work with the cells in my view, a tap and a
tap and hold gesture. I have the tap and hold gesture working like so:
-(void) longTap:(UILongPressGestureRecognizer *)gestureRecognizer
{
NSLog(@"gestureRecognizer= %@",gestureRecognizer);
if ([gestureRecognizer state] == UIGestureRecognizerStateBegan)
{
NSLog(@"longTap began");
CGPoint p = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [myTable indexPathForRowAtPoint:p];
if (indexPath == nil)
{
NSLog(@"long press on table view but not on a row");
}
else
{
NSLog(@"long press on table view at row %d", indexPath.row);
switch (indexPath.row)
{
case 0:
del.tableRowNumber = 0;
break;
case 1:
del.tableRowNumber = 1;
break;
case 2:
del.tableRowNumber = 2;
break;
case 3:
del.tableRowNumber = 3;
break;
case 4:
del.tableRowNumber = 4;
break;
case 5:
del.tableRowNumber = 5;
break;
}
}
UIViewController *controller = [self.storyboard
instantiateViewControllerWithIdentifier:@"MealPlannerRecipeTypeViewController"];
[self.navigationController pushViewController:controller
animated:YES];
}
}
I need this gesture to set a value in a singleton class to a certain value
depending on what row is selected. No matter what row is selected this
value is always 0?! Can anyone tell me why?
Second part of the question is that one of my tableview delegates looks
like this:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
RecipeInfo *recipeInfo = recipeInfoArray[indexPath.row];
cell.textLabel.text = recipeInfo.name;
// Add long tap for the main tiles
UILongPressGestureRecognizer *longPressGesture =
[[UILongPressGestureRecognizer alloc] initWithTarget:self
action:@selector(longTap:)];
[cell addGestureRecognizer:longPressGesture];
}
return cell;
}
Every row in my table view has the same information as the first one? Why
is this?
Thanks
No comments:
Post a Comment