[英]How to tell which table cell was clicked from another View Controller? iOS 7
I can't seem to find much on the net that is specific to my question. 我似乎无法在网上找到针对我的问题的很多信息。
Here's my situation; 这是我的情况; I have a Table View Controller with 5 cells that act purely as buttons that correspond to particular web sites, and each button will push to a View Controller with a web view on it, displaying the corresponding website.
我有一个包含5个单元格的Table View Controller,它们纯粹用作对应于特定网站的按钮,每个按钮将推送到带有Web视图的View Controller,显示相应的网站。
Instead of having 5 different view controllers all with their own web view on it, is there some way to programatically determine which table cell was clicked so that I can change the URL in which the Web View references? 有没有办法以编程方式确定单击了哪个表格单元,以便可以更改Web View引用的URL,而不是使用5个不同的View Controller都带有自己的Web视图。 That way I only need one View Controller and one Web View, and depending on the particular cell that was selected it will display a different website in that Web View.
这样,我只需要一个View Controller和一个Web View,并且根据所选的特定单元,它将在该Web View中显示另一个网站。 How might I do this?
我该怎么办? I just feel like it is redundant to have 5 very similar view controllers.
我只是觉得拥有5个非常相似的视图控制器是多余的。
See below for my current code and some screen shots. 有关我当前的代码和一些屏幕截图,请参见下文。
This code simply loads the URL into the web View (Websites.m) 此代码只是将URL加载到Web视图(Websites.m)中
NSURL *cpaURL = [NSURL URLWithString:@"http://www.cpagroup.com.au"]; // Define new URL variable
NSURLRequest *myRequest = [NSURLRequest requestWithURL:cpaURL]; // Define new web page request
[cpaWebView loadRequest:myRequest]; // Load request to page
cpaWebView.scalesPageToFit = YES; // Scale page to fit on the screen
Link between table and one web view 表格和一个Web视图之间的链接
Just pass the NSURL string into the webSite file ( Check here for passing data ), In your didSelectRow . 只需在您的didSelectRow中将NSURL字符串传递到webSite文件( 在此处检查是否传递数据 )即可。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// initialise your website class file
websiteObj.urlString = // Use the Array OR something which you had reference of cell data
}
And in your website class, use the urlString
to load the webView 并在您的网站类中,使用
urlString
加载webView
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.