我有一个填充了数据(文本和图像)的 UITableView。当用户点击特定的行项目时,它将转到 detailViewController,它将所选行项目的文本和图像填充到下一个 View Controller 中。
我正在使用 prepareForSegue 而不是 didSelectRowAtIndexPath。
titleForRow:indexPath.row in:indexPath.section 和 imageForRow:... 方法用于填充每个行项目的标题 (cell.textLabel.text) 和图像 (cell.imageView.image)。我没有使用数据模型,因为这只是一个显示在 detailViewController (UNFDetailLoginTableViewController) 上的模板
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"addLoginToDetailLoginTVC"])
{
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
UNFDetailLoginTableViewController *targetVC = (UNFDetailLoginTableViewController *)navController.topViewController;
NSIndexPath *indexPath = [self.addLoginTableView indexPathForCell:sender];
targetVC.loginNameTextField.text = [self titleForRow:indexPath.row in:indexPath.section];
targetVC.detailLoginImage.image = [self imageForRow:indexPath.row in:indexPath.section];
NSLog (@"%@", [self titleForRow:indexPath.row in:indexPath.section]);
}
点击特定行后,它会转到 detailLoginTableViewController,但不会填充数据。然而,NSLog 记录了应该传递给 detailLoginTableViewController 的正确数据。请帮忙。谢谢。
最佳答案
如果目标 viewController 的属性是 IBOutlets,那么由于它们在目标 View 加载之前没有设置,您需要将数据传递给中间属性,然后在 的 viewDidLoad 方法中code>targetVC 设置你的网点。
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"addLoginToDetailLoginTVC"])
{
UINavigationController *navController = (UINavigationController *)segue.destinationViewController;
UNFDetailLoginTableViewController *targetVC = (UNFDetailLoginTableViewController *)navController.topViewController;
NSIndexPath *indexPath = [self.addLoginTableView indexPathForCell:sender];
targetVC.text = [self titleForRow:indexPath.row in:indexPath.section];
targetVC.image = [self imageForRow:indexPath.row in:indexPath.section];
NSLog (@"%@", [self titleForRow:indexPath.row in:indexPath.section]);
}
在你的 UNFDetailLoginTableViewController.h 中:
@property (strong, nonatomic) NSString *text;
@property (strong, nonatomic) UIImage *image;
在您的 UNFDetailLoginTableViewController.m 中,在 viewDidLoad 中:
self.loginNameTextField.text = self.text;
self.detailLoginImage.image = self.image;
关于ios - 将单元格数据(即 cell.textlabel.text 和 cell.imageView.image)传递给另一个 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23500024/
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
所以我在关注Railscast,我注意到在html.erb文件中,ruby代码有一个微弱的背景高亮效果,以区别于其他代码HTML文档。我知道Ryan使用TextMate。我正在使用SublimeText3。我怎样才能达到同样的效果?谢谢! 最佳答案 为SublimeText安装ERB包。假设您安装了SublimeText包管理器*,只需点击cmd+shift+P即可获得命令菜单,然后键入installpackage并选择PackageControl:InstallPackage获取包管理器菜单。在该菜单中,键入ERB并在看到包时选择
我有一个正在构建的应用程序,我需要一个模型来创建另一个模型的实例。我希望每辆车都有4个轮胎。汽车模型classCar轮胎模型classTire但是,在make_tires内部有一个错误,如果我为Tire尝试它,则没有用于创建或新建的activerecord方法。当我检查轮胎时,它没有这些方法。我该如何补救?错误是这样的:未定义的方法'create'forActiveRecord::AttributeMethods::Serialization::Tire::Module我测试了两个环境:测试和开发,它们都因相同的错误而失败。 最佳答案
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
我想让一个yaml对象引用另一个,如下所示:intro:"Hello,dearuser."registration:$introThanksforregistering!new_message:$introYouhaveanewmessage!上面的语法只是它如何工作的一个例子(这也是它在thiscpanmodule中的工作方式。)我正在使用标准的rubyyaml解析器。这可能吗? 最佳答案 一些yaml对象确实引用了其他对象:irb>require'yaml'#=>trueirb>str="hello"#=>"hello"ir
我没有找到太多关于如何执行此操作的信息,尽管有很多关于如何使用像这样的redirect_to将参数传递给重定向的建议:action=>'something',:controller=>'something'在我的应用程序中,我在路由文件中有以下内容match'profile'=>'User#show'我的表演Action是这样的defshow@user=User.find(params[:user])@title=@user.first_nameend重定向发生在同一个用户Controller中,就像这样defregister@title="Registration"@user=Use
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些
如何在Ruby中按名称传递函数?(我使用Ruby才几个小时,所以我还在想办法。)nums=[1,2,3,4]#Thisworks,butismoreverbosethanI'dlikenums.eachdo|i|putsiend#InJS,Icouldjustdosomethinglike:#nums.forEach(console.log)#InF#,itwouldbesomethinglike:#List.iternums(printf"%A")#InRuby,IwishIcoulddosomethinglike:nums.eachputs在Ruby中能不能做到类似的简洁?我可以只
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里