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

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];

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];

On select of UITableViewCell Navigate to New DetailViewController

Problem: On selection of a particular uitableviewcell, a new DetailViewController should be opened. I have written the code in didSelectRowAtIndexPath but when I click on the cell it is showing me a runtime error.
I have tried calling with [self.navigationController presentModalViewController:jacket animated:YES ]; but when I do my view controller is not getting opened.
Another method I tried is by [self.navigationController performSegueWithIdentifier:#"JacketDetails" sender:self ];.
I have Specified Identifier in the segued has "JacketDetails" in the inspector but here I am getting a run yime error. I have Hooked Segue from UITABLEVIEWCELL to VIEWCONTROLLER.
When I click on the row JacketDetailViewController Should be open. I have Created Class JacketDetailViewController and for New ViewController I have set the class for this in the inspector.
I don't know why it is showing no segue , I have given the identifier in the inspector and properly hooked from tableviewcell to new view controller.
In JacketDetailViewController I want to display a list of Jackets. Presently it is blank ViewController.
My code is below. Would you please suggest a solution? I am a self-teaching beginner in this field. I might have made some minor mistakes. I have Googled my problem and tried to solve it but I have been stuck here for a few days.
TshirtDetailViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
[tableView deselectRowAtIndexPath:indexPath animated:YES ];
JacketDetailController *jacket =[[JacketDetailController alloc]init];
NSInteger index =indexPath.row;
NSLog(#"Row:%d",index);
NSString *titleString = [[NSString alloc] initWithFormat:[jackets objectAtIndex:indexPath.row]];
NSLog(#"%#",titleString);
jacket.title=titleString;
// ...
// Pass the selected object to the new view controller.
[self.navigationController performSegueWithIdentifier:#"JacketDetails" sender:self ];
// [self.navigationController presentModalViewController:jacket animated:YES ];
}
#end
Error in Console:
2013-01-07 10:52:21.020 KidsShopee[617:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<UINavigationController: 0x6a5fac0>) has no segue with identifier 'JacketDetails''
*** First throw call stack:
(0x13bf052 0x1550d0a 0xdd24b 0x3e8e 0xa671d 0xa6952 0x92e86d 0x1393966 0x1393407 0x12f67c0 0x12f5db4 0x12f5ccb 0x12a8879 0x12a893e 0x16a9b 0x1b08 0x1a65 0x1)
terminate called throwing an exception(gdb)
Try to open view with these lines:
YoutubeViewController *objYoutubeViewController = [[YoutubeViewController alloc]initWithNibName:#"YoutubeViewController" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:objYoutubeViewController animated:YES];
[objYoutubeViewController release];
In place of YoutubeViewController give your view controller class name & change these lines
According to you & check.Ok if you using storyboard then try like below:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
bookmarkViewController *myVC = (bookmarkViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:#"bookmarkViewController"]
[self presentModalViewController:myVC animated:YES];
in place of bookmarkViewController give your controller name & check. in drag & drop view
controller in main storyboard give right class name like below images:
in place of my bookmarkViewController name give your view controller name that you want to open.
Don't call performSegueWithIdentifier:sender: on the navigation controller! Only your custom viewController can have segues. Call it on self.
Replace
[self.navigationController performSegueWithIdentifier:#"JacketDetails" sender:self ];
with
[self performSegueWithIdentifier:#"JacketDetails" sender:[tableView cellForRowAtIndexPath:indexPath]];
If you hooked up a segue in the storyboard from the table view cell to another controller, then you don't need any of this code at all to make the segue fire. You should be implementing prepareForSegue to pass the information you need to the detail controller, but no other code is necessary.
Based on the error you are getting "has no segue with identifier 'JacketDetails'", something is not right with your call to the segue. I have found that I have problems with seque names working properly unless I copy and paste from the name I gave the seque in the storyboard into my .m file. Even if the spelling and case is correct, I have found many times, copying and pasting has fixed the problem.
Can try with this-
JacketDetailController *jacket =[[JacketDetailController alloc]initWithNibName:#"JacketDetailController" bundle:nil];];///Change string as your nib name.
Then if its navigation base application-
[self.navigationController pushViewController:jacket animated:YES];
Then is its viewController base application-
[self presentModalViewController:jacket animated:YES];

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.

Cannot push TTTableViewController onto Navigation Controller

I have an app where I have a TTTableView Controller inside a Navigation Controller that is Insider a TabBar.
I want it so that if a user selects an item it will push another TTTableView with the items under that category.
The code I have is
-(void)didSelectObject:(id)object atIndexPath:(NSIndexPath *)indexPath {
if ([object isKindOfClass:[TTTableMoreButton class]]) {
[super didSelectObject:object atIndexPath:indexPath];
} else {
CategoryViewController *viewController = [[CategoryViewController alloc] initWithNibName:#"CategoryViewController" bundle:nil];
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
}
}
The CategoryViewController is setup as
#interface CategoryViewController : TTTableViewController
and the CategoryViewController.xib file has the datasource & delegate set to the files owner and the view set to the tableview and the tableview class is set to TTTableView.
When I run it I get the following error when selecting a row
2011-10-17 16:18:23.819 Biz Insider[34067:f803] -[CategoryViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6c93d30
2011-10-17 16:18:23.820 Biz Insider[34067:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CategoryViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x6c93d30'
*** First throw call stack:
(0x1893052 0x157ed0a 0x1894ced 0x17f9f00 0x17f9ce2 0xb4cf2b 0xb4f722 0x9ff7c7 0x9ff2c1 0x9b61e 0xa0228c 0xa06783 0x9bb48 0x9b1301 0x1894e72 0x89192d 0x89b827 0x821fa7 0x823ea6 0x823580 0x18679ce 0x17fe670 0x17ca4f6 0x17c9db4 0x17c9ccb 0x1f88879 0x1f8893e 0x972a9b 0x273d 0x26b5)
terminate called throwing an exceptionCurrent language: auto; currently objective-c
If I try and push another view (i have one with a webview on it) then it works fine, or if I go into interface builder and link the File Owner's "tableView" to the TTTableView object it will work fine and push the controller except the "Pull down to refresh" function wont work so I am assuming that the deletage isn't correct when doing it that way.
Any help would be greatly appreciated.
EDIT:
I have a feeling that it has something to do with the following
-(id<UITableViewDelegate>)createDelegate {
return [[[TTTableViewDragRefreshDelegate alloc] initWithController:self] autorelease];
}
This sets the delegate to TTTableViewDragRefreshDelegate which implements the numberOfRowsInSection and all that junk. Is there another way to do this?
Cheers,
Dean
The log says that in your custom class CategoryViewController method tableView:numberOfRowsInSection: is not implemented and so it couldn't call it.
Check it and check types of its parameters.
Well this is an odd one, but I changed it from
CategoryViewController *viewController = [[CategoryViewController alloc] initWithNibName:#"CategoryViewController" bundle:nil];
to
CategoryViewController *viewController = [[CategoryViewController alloc] init];
and it magically works now...dont ask me how or why.
There must have been something in the NIB that was messing it up, but I dont know how the whole layout is working now with no NIB.

resize UItableView

i use this code
- (IBAction)gotostatuttableviewcontroller:(id)sender
{
[self.statutsField resignFirstResponder];
StatusTableViewController *statuttableview =[[StatusTableViewController alloc]initWithNibName:#"StatusTableViewController" bundle:nil];
statuttableview.Flynumber=statutsField.text;
[statuttableview.Flynumber retain];
[self.navigationController pushViewController:statuttableview animated:YES];
}
and this is my interface in interface builder http://hpics.li/19cc67b
But when i build , i have this
http://hpics.li/188d87e
Why the tableview don't have the same seize that i puted in interface builder ? It's becaus it' a UItableViewcontroller class and not UIViewCotroller ?
#CharlieMezak i do it and now i have this error
Terminating app due to uncaught
exception
'NSInternalInconsistencyException',
reason: '-[UITableViewController
loadView] loaded the
"StatusTableViewController" nib but
didn't get a UITableView.'
in this line ( pushviewcontroller)
StatusTableViewController *statuttableview =[[StatusTableViewController alloc]initWithNibName:#"StatusTableViewController" bundle:nil];
statuttableview.Flynumber=statutsField.text;
[statuttableview.Flynumber retain];
[self.navigationController pushViewController:statuttableview animated:YES];
Thank you
Look at your nib file. Check that the File's Owner view outlet is connected to the top level UIView and not to the UITableView. If it's connected to the table view, then the table view will be treated as the view controller's view. The containing views will be ignored.
Try setting the frame of the UITableView in viewDidLoad.