简体   繁体   English

如何判断从另一个View Controller单击哪个表格单元格? IOS 7

[英]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视图之间的链接

表格和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.

相关问题 在Swift中单击Table View的单元格时如何调用(显示)另一个View Controller - How to call (show) another View Controller when clicked on the cell of Table View in Swift 在快速的iOS 8中,当单击一个单元格时,如何获取它以打开另一个视图控制器? - In swift iOS 8 when a cell is clicked, how do I get it to open another view controller? 如何将信息从一个视图控制器中的表视图单元传递到另一视图控制器? - How do I pass information from a table view cell in one view controller to another view controller? 从另一个视图控制器以编程方式选择一个表视图单元格 - Selecting a Table View Cell programmatically from another view controller 从一个视图 controller 到另一个视图显示表格视图单元格的问题 - Issues displaying a table view cell from one view controller to another 如何使用在另一个视图控制器中输入的值填充表格视图单元格? - How to populate the table view cell with values entered in another view controller? iOS将数据从表格单元格传递到新的视图控制器 - iOS passing data from table cell to new view controller 当通过表格单元格附件在UINavigation设置中显示视图控制器时,如何知道它来自哪个表格单元格? - When showing a view controller in a UINavigation setup from a table cell accessory, how do I know which table cell it came from? iOS如何将选定的单元格值隔离到另一个视图控制器中 - iOS how to segue a selected cell value into another view controller 如何将选定的collectionview单元格发送到另一个视图控制器(ios)? - How to send a selected collectionview cell to another view controller (ios)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM