0

我有一个表视图加载一个 sqldata 文件,该文件在单元格中显示标签和图像。我希望将图像和其他数据加载到下一个 vc 中,但似乎甚至无法获取日志来拉回文件时间,因此没有机会将其推过。这一切都是以编程方式完成的,所以发现它有点困难。所有帮助表示赞赏!!!!

//表格视图

   - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath >*)indexPath {

       [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

       ATPictureViewController *newView = [[ATPictureViewController alloc] init];
       
       newView.mainImageView.image=[tableView >cellForRowAtIndexPath:indexPath].imageView.image ;
       
       [self.navigationController pushViewController:newView animated:YES];
       
      // NSLog(@"Log33 %@",);
   }

   @end
   

我以为就是这样

newView.mainImageView.image=[tableView cellForRowAtIndexPath:indexPath].imageView.image;

但什么也没给我

    //vc.h
   
   #import <UIKit/UIKit.h>
   
   @interface ATPictureViewController : UIViewController{
       
       UIImageView *mainImage;
   }
   
   @property (strong, nonatomic) UIImageView *mainImageView;
   
   @end

不知道我是否在这里打电话

   //vc.m
   
   - (void)viewDidLoad
   {
       [super viewDidLoad];
       
       self.mainImageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 200,    200)];
       [self.view addSubview:self.mainImageView];
       
       self.mainImageView.image = ???????????
       
4

1 回答 1

1

至少有一个问题,也许有两个。首先,您不能在 didSelectRowAtIndexPath 方法中设置 mainImageView 的图像,因为此时尚未加载 ATPictureViewController 的视图,并且其 mainImageView 属性将为 nil。相反,您应该在 ATPictureViewController 中创建一个 UIImage 属性,并将其值分配给 didSelectRowAtIndexPath 中的 [tableView cellForRowAtIndexPath:indexPath].imageView.image。然后可以在 ATPictureViewController 的 viewDidLoad 方法中设置 mainImageView 的图像。

另一个可能的问题是使用 alloc init 来实例化 newView。根据您为该控制器创建视图的位置,您可能会得到一个空白视图。你应该使用 initWithNibName:bundle: 如果你让你在 xib 中查看,或者 instanceViewControllerWithIdentifier: 如果你在故事板中创建它。

于 2013-09-19T03:27:34.613 回答