1

我有一个应用程序,它显示tableview图像和一些细节。我正在努力做到这一点,当有人触摸我的表格视图中显示的图像时,应用程序会以更大的尺寸打开相同的图像,并能够在它们之间导航。

这是我当前的代码:

singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imgTapped:)];

singleTap.numberOfTapsRequired =1;
singleTap.numberOfTouchesRequired = 1;

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    return [json count];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];

    if(cell == nil){

        [[NSBundle mainBundle] loadNibNamed:@"AgendaCell" owner:self options:nil];
        cell = self.agendaCell;

    }

    agendaCell.dateCell.text = [[json objectAtIndex:[indexPath row]] objectForKey:@"date"];
    agendaCell.enderecoCell.text = [[json objectAtIndex:[indexPath row]] objectForKey:@"endereco"];
    agendaCell.tituloCell.text = [[json objectAtIndex:[indexPath row]] objectForKey:@"titulo"];
    [agendaCell.imgCell setImageWithURL:[NSURL URLWithString:@"http://sallescds.com.br/wp-content/uploads/2012/12/xepop-300x300.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    [agendaCell.imgCell setUserInteractionEnabled:YES];
    [agendaCell.imgCell addGestureRecognizer:singleTap];


    return cell;
}

这是点击图像时的功能:

-(void)imgTapped:(UIGestureRecognizer *)gestureRecognizer{

    NSLog(@"detectado o click no UIImageView BITCH!");

    IMGDetailViewController *imgView = [[IMGDetailViewController alloc] initWithNibName:@"IMGDetailViewController" bundle:nil];


    [self.navigationController pushViewController:imgView animated:YES];
}

当我尝试这个时,应用程序就会崩溃。

4

1 回答 1

0

我不知道你是如何设置agendaCell的,但通常会说:

if (cell == nil) {
    [[NSBundle mainBundle] loadNibNamed:@"AgendaCell" owner:self options:nil];
    cell = self.agendaCell;
}

将会:

if (cell == nil) {
    NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"AgendaCell" owner:self options:nil];
    cell = [nibObjects objectAtIndex:0];
}

请参阅如何从 Xib 文件加载自定义 UITableViewCells?

于 2013-05-21T21:45:31.157 回答