Trying to pass from TableView to UIWebview causes crashes - iphone

As you can read in the title, I am having a slight problem. I am using the MWParser for an RSS feed. I edited the code for when you click on an RSS title, it opens in an in-app browser.
This is the code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (_webViewController == nil) {
self.webViewController = [[[WebViewController alloc] initWithNibName:#"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
}
MWFeedItem *entry = [parsedItems objectAtIndex:indexPath.row];
_webViewController.entry = entry;
[self.navigationController pushViewController:_webViewController animated:YES];
// Deselect
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
However, I get this crash message:
2013-02-11 18:21:15.644 GlennKessler[24209:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/Hugo/Library/Application Support/iPhone Simulator/6.1/Applications/7F35D6C0-BFBE-4CD9-A1CE-7DC54CD6B249/GlennKessler.app> (loaded)' with name 'WebViewController''
From what I can tell, this is happening because I am using Storyboards, not NIBs. How do I have it open the view in the storyboard that is running off of the code in WebViewController? Thanks!

Replace the [NSBundle mainBundle] by nil since the nib is in the default bundle, and make sure that the nib file (WebViewController.nib) is in the Bundle you are packaging the app

Related

While transition the page after click, screen is going black

here is my code:
I using storyboards
NewsDetailViewController *newsdetail=[[NewsDetailViewController alloc] initWithNibName:nil bundle:nil];
newsdetail.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:newsdetail animated:YES];
I have a collectionview i fetched some datas from api and put them to the cells of collectionview. I want to get details of items that i clicked on cell but after click details doesn't work but black screen is coming.
here is my all output :
2013-06-17 14:20:30.288 xproject[7511:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/sezgindemir/Library/Application Support/iPhone Simulator/6.1/Applications/67BC91AF-5091-4F39-A2BD-CA7E1DD0FEF0/xproject.app> (loaded)' with name 'NewsDetailViewController''
*** First throw call stack:
(0x1c99012 0x10d6e7e 0x1c98deb 0x236ef9 0xfb7e7 0xfbdc8 0xfbff8 0xfc232 0x107c25 0x3073a3 0x104ee3 0x105167 0x1051a7 0x4c3d 0x51c42f 0x52e182 0x52e394 0x10ea705 0x12893c 0x1289ac 0x10ea705 0x12893c 0x1289ac 0x2e21d3 0x1c61afe 0x1c61a3d 0x1c3f7c2 0x1c3ef44 0x1c3ee1b 0x1bf37e3 0x1bf3668 0x1affc 0x25ed 0x2515)
libc++abi.dylib: terminate called throwing an exception
(lldb)
Is the xib for NewsDetailViewController in storyboard or separate xib?
If it is a separate xib, make sure your xib name is NewsDetailViewController.xib. Then it should work.
If the nib is in storyboard the
first set the storyboardID of the xib to NewsDetailViewController and then use
NewsDetailViewController *newsdetail=[[self storyboard] instantiateViewControllerWithIdentifier:#"NewsDetailViewController"];
newsdetail.modalTransitionStyle=UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:newsdetail animated:YES];
You're not loading view controller properly.
Try this code:
UIViewController *vc=[[self storyboard] instantiateViewControllerWithIdentifier:#"NewsDetail"];//you have to give it this name (or any) in the storyboard
[self.navigationController pushViewController:vc animated:YES];
Make sure you have a uinavigationController controlling self
I think you missed to provide the NibName
Your code
NewsDetailViewController *newsdetail=[[NewsDetailViewController alloc] initWithNibName:nil bundle:nil];
It should be
NewsDetailViewController *newsdetail=[[NewsDetailViewController alloc] initWithNibName:#"YOUR_NIB_NAME" bundle:nil];
Use this -
NewsDetailViewController *news detail = [[NewsDetailViewController alloc] init];

Switch to a new viewcontroller after validation from log in server

I am trying to make an app when I use a log in screen and I communicate to a server.
When I connect to the server it returns me a value true if my log in is correct or false if its incorrect.
Then I try to make the app to switch in a new UIViewController (after I press the log in button) if only the log in is correct.
For that I store the value that server returns in a string and compare that with another and implement the UIViewController switch.
After running my app I get an error
:Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:
Could not load NIB in bundle: 'NSBundle </Users/dimitriskoumouras/Library/Application Support/iPhone
Simulator/6.0/Applications/9E756F03-38C1-453C-A26E-497AA7DDAECA/Administrator.app> (loaded)'
with name 'FourthViewController.xib''!!
Posting some code :
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data {
NSLog(#"EWYFPicOneViewController - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data {");
string = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
NSLog(#" data == %#",string);
NSString *compare = [NSString stringWithFormat:#"true"];
if ( [compare isEqualToString:string]) {
UIViewController* FourthViewController = [[UIViewController alloc] initWithNibName:#"FourthViewController.xib" bundle:[NSBundle mainBundle]];
[self.view addSubview:FourthViewController.view];
}
else
NSLog(#"validation not complete");
}
Any thoughts?? (i start to think that maybe my whole logic is wrong)..
Thanks in advance!!
Try this after parsing...
if ( [compare isEqualToString:string]) {
UIViewController* FourthViewController = [[UIViewController alloc] initWithNibName:#"FourthViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:FourthViewController animated:YES];
}
and also use this....
UIViewController* FourthViewController = [[UIViewController alloc] initWithNibName:#"FourthViewController" bundle:[NSBundle mainBundle]];
[self.view addSubview:FourthViewController.view];
After running my app i get an error :Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'FourthViewController.xib''
xib files are xml nib files and they are compiled into nibs. So your should load FourthViewController.nib (or simply remove the extension).
Remove xib from this line first & then check: initWithNibName:#"FourthViewController.xib"

Error when trying to load next View from nib

This is what I'm trying to do in TalbeViewController.m:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:TRUE];
if(indexPath.row==0) {
//Initialize the detail view controller and display it.
OmDetail1ViewController *firstDetailController = [[OmDetail1ViewController alloc] initWithNibName:#"OmDetail1ViewController" bundle:nil];
[self.navigationController pushViewController:firstDetailController animated:YES];
[firstDetailController release];
}
else if(indexPath.row==1) {
//The second DetailView
}
else if(indexPath.row==2) {
//The third DetailView
}
}
And this is what I'm told when the first cell is selected:
2012-07-17 14:17:42.660 TheApp[4635:f803] * * * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'OmDetail1ViewController''
* First throw call stack:
(0x13d5022 0x1566cd6 0x137da48 0x137d9b9 0x240638 0xe61fc 0xe6779 0xe699b 0xe6d11 0xf88fd 0xf8aef 0xf8dbb 0xf985f 0xf9e06 0xf9a24 0x2f90 0xb05c5 0xb07fa 0x94585d 0x13a9936 0x13a93d7 0x130c790 0x130bd84 0x130bc9b 0x12be7d8 0x12be88a 0x1f626 0x28c2 0x2835)
terminate called throwing an exception(lldb)
I've done nothing else to connect the views except importing "OmDetail1ViewController.h" in TableViewController.m.
In the IB I've set the correct Class in the utilites but done nothing more, made no connections or so.
The problem is not in that piece of code. But rather in your OmDetail1ViewController class, check that you have set the view correctly in IB for the ViewController, and that the name matches.
In IB your view should be set to "Files Owner" and if you select Files Owner, in the Custom Class it should have your OmDetail1ViewController class.

How to use didSelectRowAtIndexPath in objective-c

I have a Tab Bar with a navigation table view. My app crashes when I select a cell on my table view. I want a new viewcontroller to open when a cell is selected. My guess is that I am not pushing it correctly when didselectrowatindexpath is called. The app stays hung up for a few seconds then closes.
Does anything catch your eye with this code? Or do you have any sample code? I am using Xcode 3 with simulator 4.3.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
if (self.vailViewController == nil) {
VailViewController *vailView = [[VailViewController alloc] initWithNibName:#"View" bundle:nil];
self.vailViewController = vailView;
[vailView release];
}
vailViewController.title = [NSString stringWithFormat:#"%#", [resortsArray objectAtIndex:row]];
Ski_AdvisorAppDelegate *delegate = (Ski_AdvisorAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.resortsNavController pushViewController:vailViewController animated:YES];
[self.navigationController pushViewController:vailViewController animated:YES];
}
Thanks a lot!
if (self.vailViewController == nil) {
VailViewController *vailView = [[VailViewController alloc] initWithNibName:#"View" bundle:nil];
self.vailViewController = vailView;
[vailView release];
}
In this block of code is your view file actually named "View.xib" because if not this is your crash. With this error message
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'View''
So if you want to load this with initWithNibName and your files are named as such:
VailViewController.h
VailViewController.m
VailViewController.xib
you need:
VailViewController *vailView = [[VailViewController alloc] initWithNibName:#"VailViewController" bundle:nil];
However if it is a standard UIViewController subclass you should only need to do:
VailViewController *vailView = [[VailViewController alloc] init];
The above works if you just created a UIViewController subclass in Xcode and didn't change anything. The view controller knows how to load it's own view. If you had it create an .xib file for you and you deleted something in it or just arn't sure make sure the File's Owner is wired up to the root view in the .xib file in interface bulder.
I hope that helps.
Edit:
The error in your comments:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported
is coming these two lines in your code:
[delegate.resortsNavController pushViewController:vailViewController animated:YES];
[self.navigationController pushViewController:vailViewController animated:YES];
I should ask if these are two different navigation controllers? if so why do they need the exact same view controller pushed to them?
I would remove one of them and then it should push the view controller without error.
What is aBookDetail? It seems like you might not be pushing the VailViewController onto the stack like you think you are. The code below might be more what you want. Also, does the debugger give you any error information about the crash?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
if (self.vailViewController == nil) {
VailViewController *vailView = [[VailViewController alloc] initWithNibName:#"View" bundle:nil];
self.vailViewController = vailView;
[vailView release];
}
self.vailViewController.title = [NSString stringWithFormat:#"%#", [resortsArray objectAtIndex:row]];
Ski_AdvisorAppDelegate *delegate = (Ski_AdvisorAppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.resortsNavController pushViewController:self.vailViewController animated:YES];
}
Ensure the vailViewController is being retained.
#property (retain) VailViewController *vailViewController;
Also, is the resortsNavController off of Ski_AdvisorAppDelegate retained? How is that property defined?
Also, is the UITableViewController the rootController of the UINavigationController? If so, you should be able to call [self navigationController]
[[self navigationController] pushViewController:detailedView animated:YES];
I typically do this in my appDelegate:
_mainTableViewController = [[MainTableViewController alloc] init];
_navController = [[UINavigationController alloc] initWithRootViewController:_mainTableViewController];

iPhone: App crashes when I click on a cell in table view

Compiling my application works—everything is fine. The only errors I get are by deprecated functions (setText).
The only problem is now, is that when I tap on a cell in my table, the app crashes, even though it's meant to push to the next view in the stack.
Any solutions are appreciated, if you need any code, just ask.
Also, how can I only make sure that one cell goes to only one view? For example:
When I tap on CSS, it takes me to a new table with different levels of CSS. WHen I tap on an item in that new view, it comes up with an article on what I just selected.
Regards,
Jack
Here's my code at the didSelectRowAtIndexPath method:
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row==0){
NextViewController *nextController = [[NextViewController alloc]
initWithNibName:#"NextView" bundle:nil];
[self.navigationController pushViewController:nextController
animated:YES];
[nextController changeItemTable:[arryClientSide
objectAtIndex:indexPath.row]];
}
}
#end
(as requested in the comments).
When we create new UIViewControllerSubClass with xib-interface, xib file is created as sourcecode.xib (can be seen in get info of that xib file): Change sourcecode.xib to "file.xib" and see the magic :)
Terminating app due to uncaught
exception
'NSInternalInconsistencyException',
reason: -[UIViewController
_loadViewFromNibNamed:bundle:] loaded the "NextView" nib but the view outlet
was not set.'
Open NextView with Interface Builder
Set Class value at : "NextViewController" to your File's Owner
Connect the View outlet (Ctrl click and drag - a blue line should appear - from the File Owner to the UIView and select "view" in options)
you need to update your code like this :
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row==0){
NextViewController *nextController = [[NextViewController alloc]
initWithNibName:#"NextView" bundle:nil];
[nextController changeItemTable:[arryClientSide
objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:nextController
animated:YES];
}
else{ }
}
try using this code...
Error description from comments:
Terminating app due to uncaught
exception
'NSInternalInconsistencyException',
reason: '-[UIViewController
_loadViewFromNibNamed:bundle:] loaded the "NextView" nib but the view outlet
was not set.'
If your view controller is loaded from nib file and its view is not set exception then exception is thrown. So when you create your view in IB you must connect view outlet to your view controller object (likely - file owner in IB).
Edit: So basically in IB in your nib file you need to do the following:
1. set file owner's type to NextViewController
2. connect NextViewController's view outlet to a View object
release that NextViewController you alloc!
[nextController release];
It's leaking.
Don't use IB. Instead, make alloc init with nothing, then in load view:
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];