尝试在tabviewcontroller序列中加载从前一个viewcontroller传递的url。检查通常的嫌疑人。 UIWebview添加了视图插座。所有适当的代表都已连接。我不确定NSURL是否会被传递到下一个视图控制器,因为我得到一个黑屏(尽管响应对象不是nil)。它让我发疯,因为这是一个简单的问题而且这是我做过数百万次的事情,但它不起作用。任何帮助,将不胜感激。
下面你会找到代码。
SquirrelInformationTableViewController.m
@interface ASAInformationTabViewController (){
NSMutableArray *squirrelArray;
}
@property (nonatomic, strong) ODRefreshControl *refreshControl;
@property (weak, nonatomic) IBOutlet UITableView *squirrelListTableView;
@end
@implementation ASAInformationTabViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setUpSquirrelList];
//Add drag to refresh function
self.refreshControl = [[ODRefreshControl alloc]initInScrollView:self.squirrelListTableView];
self.refreshControl.tintColor = [UIColor colorWithRed:46.0/255 green:172.0/255 blue:247.0/255 alpha:1];
[self.refreshControl addTarget:self action:@selector(dragToRefreshAction:) forControlEvents:UIControlEventValueChanged];
}
-(void)setUpSquirrelList
{
__weak UITableView* weaktable = self.squirrelListTableView;
[[ASASquirrelManager instance] listSquirrels:^(NSString *response, NSMutableArray *result) {
if ([response isEqualToString:CODE_SUCCESS]) {
squirrelArray = result;
dispatch_async(dispatch_get_main_queue(), ^{
if (weaktable) {
[weaktable reloadData];
}
});
}
}];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ASASquirrelInformationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"squirrelIdentifier"];
ASASquirrelModel *squirrelLocal = squirrelArray[indexPath.row];
cell.squirrelTitleLabel.text = squirrelLocal.title;
cell.squirrelDescLabel.text = squirrelLocal.desc;
NSData *imageData = [[NSData alloc] initWithContentsOfURL:
[NSURL URLWithString:squirrelLocal.image]];
cell.squirrelImage.image = [UIImage imageWithData:imageData];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
ASASquirrelModel *squirrelWebLocal = squirrelArray[indexPath.row];
NSString *squirrelURLString = squirrelWebLocal.url;
//create an array with the string you want an access it
NSLog(@"%@", urlStringArray);
//Create a string from the URL pass it to the sdvc.string
SquirrelDetailViewController *sdvc = [SquirrelDetailViewController new];
sdvc.urlString = squirrelURLString;
[self.navigationController pushViewController:sdvc animated:YES];
}
SquirrelDetailViewController.m
@interface SquirrelDetailViewController () <UIWebViewDelegate>
@end
@implementation SquirrelDetailViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.webView.frame = self.view.bounds;
[self.view addSubview:self.webView];
}
-(void)viewWillAppear:(BOOL)animated
{
self.urlstr = [NSURL URLWithString:self.urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:self.urlstr];
[self.webView loadRequest:requestObj];
}
答案 0 :(得分:0)
我认为你需要使用故事板创建sdvc
的实例,否则它将无法正确实例化。所以:
SquirrelDetailViewController *sdvc =
(SquirrelDetailViewController *)[[UIStoryboard storyboardWithName:@"XXX" bundle:nil] instantiateViewControllerWithIdentifier:@"YYY"];
其中XXX是您的故事板名称,YYY是SquirrelDetailViewController的故事板标识符。
答案 1 :(得分:0)
我发现问题是我没有准备segue。 (打前额*)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:@"webviewpush" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"webviewpush"]) {
// Get destination view
SquirrelDetailViewController *vc = [segue destinationViewController];
NSIndexPath *path = [self.squirrelListTableView indexPathForSelectedRow];
ASASquirrelModel *squirrelWebLocal = squirrelArray[path.row];
NSString *squirrelURLString = squirrelWebLocal.url;
vc.urlString = squirrelURLString;
}
}
如果你原谅我,我现在就要自己淹死了。