我是iOS及其开发人员的新手。我正在开发iPhone应用程序。我有UITableView和UIWebView。当我按下UITableview的单元格时,根据点击那里我想在我的UIWebView中加载各种网页。请在下面找到我所得到的错误。
2014-07-05 08:25:59.319 WADTourisum[432:60b] myUrl-->2
2014-07-05 08:26:02.753 WADTourisum[432:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'Main.storyboard' in bundle NSBundle </Users/venushka/Library/Application Support/iPhone Simulator/7.1/Applications/3325DB09-FC4D-4B28-8DAF-5F9ABCAB8464/WADTourisum.app> (loaded)'
*** First throw call stack:
(
0 CoreFoundation 0x01a421e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x0158f8e5 objc_exception_throw + 44
2 UIKit 0x007b3400 -[UIStoryboard name] + 0
3 WADTourisum 0x0001411e -[Essentialinfocontroller tableView:didSelectRowAtIndexPath:] + 174
4 UIKit 0x003399a1 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1513
5 UIKit 0x00339b14 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 279
6 UIKit 0x0033e10e __38-[UITableView touchesEnded:withEvent:]_block_invoke + 43
7 UIKit 0x0026d0aa ___afterCACommitHandler_block_invoke + 15
8 UIKit 0x0026d055 _applyBlockToCFArrayCopiedToStack + 403
9 UIKit 0x0026ce76 _afterCACommitHandler + 532
10 CoreFoundation 0x01a0a36e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
11 CoreFoundation 0x01a0a2bf __CFRunLoopDoObservers + 399
12 CoreFoundation 0x019e8254 __CFRunLoopRun + 1076
13 CoreFoundation 0x019e79d3 CFRunLoopRunSpecific + 467
14 CoreFoundation 0x019e77eb CFRunLoopRunInMode + 123
15 GraphicsServices 0x03a365ee GSEventRunModal + 192
16 GraphicsServices 0x03a3642b GSEventRun + 104
17 UIKit 0x0024ff9b UIApplicationMain + 1225
18 WADTourisum 0x00004d1d main + 141
19 libdyld.dylib 0x02089701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Essentialinfocontroller.m
#import "Essentialinfocontroller.h"
@interface Essentialinfocontroller ()
@end
@implementation Essentialinfocontroller
@synthesize myWebview;
@synthesize courses;//dictionary type object
@synthesize coursekeys; //array type object
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *myfile= [[NSBundle mainBundle]pathForResource:@"essentialinfo" ofType:@"plist"];
// NSLog(@"testing path %@",myfile);
courses=[[NSDictionary alloc]initWithContentsOfFile:myfile];
coursekeys =[courses allKeys];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [courses count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell * cell=[[ UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
NSString * currentCourseName =[coursekeys objectAtIndex:[indexPath row]];
[[cell textLabel]setText:currentCourseName];
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
//implement stack method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==0){
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main.storyboard" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"story"];
[self.navigationController pushViewController:viewController animated:YES];
}
if (indexPath.row==1) {
NSLog(@"myUrl-->2 ");
}
}
//end
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
DetailViewController.m
@implementation DetailViewController
@synthesize info;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url= [NSURL URLWithString:@"http://www.google.lk"];
NSURLRequest * requestURL= [NSURLRequest requestWithURL:url];
[info loadRequest:requestURL];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
@end
答案 0 :(得分:2)
此行引发异常:
DetailViewController *temp =[[DetailViewController alloc]initWithNibName:@"DeatailViewController" bundle:[NSBundle mainBundle]];
上面的行使用nib文件(.xib)初始化视图控制器
正如您在评论中所说,您使用的是故事板,因此您应该使用UIStoryboard Class
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MyStoryboard" bundle:nil];
UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"DetailViewController identifier"];
现在,要获取视图控制器的标识符:
修改:
我认为你的故事板的名称是错误的。在您的项目中,您有一个名为Main.storyboard或somethingElse.storyboard的文件,因此您应该在此行中替换 storyboard :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"storyboard" bundle:nil];
主要或 somethingElse 没有.storyboard扩展程序
然后用视图控制器的标识符替换此行UIViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"DetailViewController identifier"];
中的 DetailViewController标识符(屏幕截图中的故事)
答案 1 :(得分:1)
DetailViewController
@property(nonatomic,retain)NSString *myurl;
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url= [NSURL URLWithString:myurl];
NSURLRequest * requestURL= [NSURLRequest requestWithURL:url];
[info loadRequest:requestURL];
}
Essentialinfocontroller
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==0){ //what ever you want row
DetailViewController *temp =[[DetailViewController alloc]initWithNibName:@"DeatailViewController" bundle:nil];
//or [[DetailViewController alloc]init];
temp.myurl = @"http://www.google.lk";
[self.navigationController pushViewController:temp animated:YES];
}
}