从表视图中获取行



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

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];
}
NSIndexPath *index = [NSIndexPath indexPathForRow:iboImageView.tag inSection:0];

你给出正确的索引路径吗?

NSIndexPath *myIP = [[NSIndexPath alloc] indexPathForRow:0 inSection: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];

}

最新更新