我以编程方式创建了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。
答案 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];