如何通过UInavigationcontroller在另一个viewcontroller上显示完整的选定表格单元格

时间:2015-11-30 11:06:50

标签: ios iphone xcode uitableview

我以编程方式创建了tableview,我喜欢在另一个视图控制器上显示相同的选定表格单元格(视图)。我的意思是我喜欢显示选定的特殊细胞视图。我只需要使用导航控制器。

- (void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WriteSuggestionController *writeSuggst=[[WriteSuggestionController alloc]init];


    UITableViewCell *myCell = [theTableView cellForRowAtIndexPath:indexPath];
    // Access accessory View  as below.
    writeSuggst.bottomView=myCell.accessoryView;

    [self.navigationController pushViewController:writeSuggst animated:YES];


}

我看到一种方法但是,我不知道如何从另一种观点回到cel。

2 个答案:

答案 0 :(得分:0)

由于您只想在下一个View Controller中显示单元格内容,因此最好只将屏幕截图发送到下一个View Controller。您可以在writeSuggst VC中创建名为cellImg的属性。同样在您的第一个VC中,您需要创建一个名为viewImage UIImage类型的强大属性。然后这样做:

- (void)tableView:(UITableView *)theTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        WriteSuggestionController *writeSuggst=[[WriteSuggestionController alloc]init];

    UITableViewCell *myCell = [theTableView cellForRowAtIndexPath:indexPath];
    // Access accessory View  as below.

    UIGraphicsBeginImageContext(cell.contentView.frame.size);

    [myCell.contentView.layer renderInContext:UIGraphicsGetCurrentContext()];

    self.viewImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();
    writeSuggst.cellImg = self.viewImage;
    [self.navigationController pushViewController:writeSuggst animated:YES];


}

在writeSuggst VC的viewDidLoad()中,写下以下行:

UIImageView *myCellImageView = [[UIImageView alloc] init];
CGRect frame = CGRectMake(0,0,yourWidth, yourHeight);//e.g. for a fullscreen width and 30 px height, you will write (0,0,self.view.frame.size.width,30)
myCellImageView.frame = frame;
myCellImageView.image = self.cellImage;
[self.view addSubview:myCellImageView];

答案 1 :(得分:0)

在WriteSuggestionController中创建一个属性,

@property (assign/copy) UITableViewCell *destCell;

然后,在推送视图控制器之前,将myCell值设置为destCell。

writeSuggst.destCell = mycell;
[self.navigationController pushViewController:writeSuggst animated:YES];