我似乎无法在网上找到针对我的问题的很多信息。
这是我的情况;我有一个包含5个单元格的Table View Controller,它们纯粹用作对应于特定网站的按钮,每个按钮都将推送到带有Web视图的View Controller,显示相应的网站。
有没有办法以编程方式确定单击了哪个表格单元,以便我可以更改Web视图引用的URL,而不是使用5个不同的视图控制器来全都拥有自己的Web视图?这样,我只需要一个View Controller和一个Web View,并且根据所选的特定单元,它将在该Web View中显示另一个网站。我该怎么办?我只是觉得拥有5个非常相似的视图控制器是多余的。
请参阅下面的我当前的代码和一些屏幕截图。
此代码只是将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
表格和一个Web视图之间的链接
最佳答案
只需将NSURL字符串传递到webSite文件(Check here for passing data)中的didSelectRow中即可。
- (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
}
在您的网站类中,使用
urlString
加载webView关于ios - 如何判断从另一个View Controller单击哪个表格单元格? IOS 7,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25073631/