0

到目前为止,我已经编写了下一个代码:

UITableView *tableView = (UITableView *)iboTableView;

MovieCell *cell = (MovieCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathWithIndex:iboImageView.tag]];

我不明白为什么代码崩溃?我知道单元格是什么类型,知道索引,并且有 iboTableView。

附言

在此功能中,一切正常:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    MovieCell *cell = (MovieCell *)[tableView cellForRowAtIndexPath:indexPath];
}

编辑:

-(void)tapDetected:(UITapGestureRecognizer *)sender
{
UIImageView *iboImageView = sender.view;
UIAlertView *messageAlert = [[UIAlertView alloc]
                             initWithTitle:@"Row Selected" message:[NSString stringWithFormat:@"%d", iboImageView.tag] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

// Display Alert Message
[messageAlert show];
UITableView *tableView = (UITableView *)iboTableView;
NSIndexPath *index = [NSIndexPath indexPathWithIndex:iboImageView.tag];
MovieCell *cell = (MovieCell *)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathWithIndex:iboImageView.tag]];
//DemoTableController *controller = [[DemoTableController alloc] initWithStyle:UITableViewStylePlain];
//FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:controller];
//popover.contentSize = CGSizeMake(150,158);
//[popover presentPopoverFromView:cell.iboPopImage];
}
4

3 回答 3

1
NSIndexPath *index = [NSIndexPath indexPathForRow:iboImageView.tag inSection:0];
于 2013-10-22T12:41:56.273 回答
0

你给出正确的 indexPath 吗?

NSIndexPath *myIP = [[NSIndexPath alloc] indexPathForRow:0 inSection:0];
于 2013-10-22T12:38:07.170 回答
0

试试这个:

  - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  NSIndexPath *index = [NSIndexPath indexPathForRow:iboImageView.tag inSection:0];
  NSInteger selectedRow = [tableView selectRowAtIndexPath:index animated:YES scrollPosition:nil];
 //MovieCell *cell = (MovieCell *)[tableView cellForRowAtIndexPath:indexPath];

}

于 2013-10-22T12:59:39.903 回答