从TableView获取行

时间:2013-10-22 12:33:19

标签: iphone objective-c xcode custom-controls

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

UITableView *tableView = (UITableView *)iboTableView;

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

我无法理解为什么代码崩溃了?我知道单元格是什么类型,知道索引,并且有iboTableView。

P.S。

在这个功能中,一切都有效:

- (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];
}

3 个答案:

答案 0 :(得分:1)

NSIndexPath *index = [NSIndexPath indexPathForRow:iboImageView.tag inSection:0];

答案 1 :(得分:0)

您是否提供了正确的indexPath?

NSIndexPath *myIP = [[NSIndexPath alloc] indexPathForRow:0 inSection:0];

答案 2 :(得分: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];

}