简体   繁体   English

无法从tableview加载detailViewController

[英]Cant load detailViewController from tableview

I have a table view loading a sqldata file that displays labels and a image in the cells. 我有一个加载sqldata文件的表视图,该文件在单元格中显示标签和图像。 I wish to load th image and other data into the next vc but cant seem to even get a log to pull back the file time so have no chance of pushing it over. 我希望将图像和其他数据加载到下一个vc中,但似乎什至无法获得日志来拉回文件时间,因此没有机会将其推后。 It is all being done programatically so finding it a little harder. 都是以编程方式完成的,因此很难找到它。 All help appreciated!!! 所有帮助表示赞赏!!!

//Table view //表格视图

  - (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 

I thought this was it 我以为是这样

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

but brings me nothing 但是什么都没带给我

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

not sure if i call something here 不知道我是否在这里打电话

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

There is at least one problem, maybe two. 至少有一个问题,也许是两个。 First, you can't set the image of mainImageView in your didSelectRowAtIndexPath method, because ATPictureViewController's view hasn't been loaded at that point, and its mainImageView property will be nil. 首先,您不能在didSelectRowAtIndexPath方法中设置mainImageView的图像,因为那时尚未加载ATPictureViewController的视图,并且其mainImageView属性将为nil。 Instead, you should create a UIImage property in ATPictureViewController, and assign the value of that to [tableView cellForRowAtIndexPath:indexPath].imageView.image in didSelectRowAtIndexPath. 相反,您应该在ATPictureViewController中创建UIImage属性,并将其值分配给didSelectRowAtIndexPath中的[tableView cellForRowAtIndexPath:indexPath] .imageView.image。 You can then set the image of mainImageView in ATPictureViewController's viewDidLoad method. 然后,您可以在ATPictureViewController的viewDidLoad方法中设置mainImageView的图像。

Another possible problem is using alloc init to instantiate newView. 另一个可能的问题是使用alloc init实例化newView。 Depending on where you made your view for that controller, you'll probably get a blank view. 根据为该控制器创建视图的位置,您可能会得到空白视图。 You should probably use initWithNibName:bundle: if you made you view in a xib, or instantiateViewControllerWithIdentifier: if you made it in a storyboard. 您可能应该使用initWithNibName:bundle:如果您是在xib中查看的,或者您可以使用InstantiateViewControllerWithIdentifier:如果是在情节提要中进行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从NSMutableArray将照片加载到DetailViewController - Load photos to DetailViewController from NSMutableArray 如何从DetailViewController重新加载MasterView Controller TableView - How to reload MasterView Controller TableView from DetailViewController 从DetailViewController弹出后重新加载TableView数据 - Reloading TableView Data after pop From DetailViewController 带有DetailViewController的Xcode 5 iOS 7 TableView - Xcode 5 iOS 7 TableView with DetailViewController 从tableview到detailviewcontroller故事板问题 - tableview to detailviewcontroller storyboard issue 将parse.com云后端数据从TableView传递到DetailViewController - Pass parse.com cloud backend data from TableView to DetailViewController 从iOS5中的TableView将数据传递到DetailViewController时出现问题 - Problems passing data to a DetailViewController from TableView in iOS5 在Swift中从视图控制器之间传递数据(从TableView到DetailViewController) - Passing data between View Controllers in Swift (From TableView to DetailViewController) ISplitViewController:DetailViewController可以从MasterVIewController加载数据而不需要回传吗? - ISplitViewController: Can DetailViewController load data from MasterVIewController without segueing back? 以编程方式从另一个DetailViewController中的表中推送一个DetailViewController - pushing a DetailViewController from a table in another DetailViewController programatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM