Cannot push TTTableViewController onto Navigation Controller - iphone

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.

Related

Swapping views inside a tabview controller

I have an app based on a tabBar controller. Within a certain view I'd like to add swipe gesture recognition and swap the current view with another one (which is not part of the tabBarController array). I have tried:
- (IBAction)swipeLeftDetected:(UIGestureRecognizer *)sender
{
//Does not work
UIViewController *DesiredViewController =[[UIViewController alloc] initWithNibName:#"DesiredViewController" bundle:nil];
DesiredViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:DesiredViewController animated:YES];
[self.view addSubview:DesiredViewController.view];
}
but the program crashes. The error I get is related to a SegmentedControl which is present in the next view but is absent in the current one. The views independently work perfectly!
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason:'[<UIViewController 0xa355fb0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key X_SegmentedControl.'
I don't understand what I am doing wrong.. I want to swap the views completely rather than putting one on top of each other. Any advice please? Thanks
instead use this
-(IBAction)swipeLeftDetected:(UIGestureRecognizer *)sender
{
DesiredViewController *objView =[[DesiredViewController alloc]initWithNibName:#"DesiredViewController" bundle:nil];
objView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:objView animated:YES];
[objView release]; // use release if using Non-ARC
}
The problem is not about the transition.
You are loading a view controller from a NIB.
A view controller is usually subclassed, so (assuming that your nib is configured correctly and you have .h and .m implementation file for your DesiredViewController subclass) you should init like this:
DesiredViewController *controllerInstance =[[DesiredViewController alloc] initWithNibName:#"DesiredViewController" bundle:nil];
The exception is because you probably have a segmented control inside your view controller subclass, Xcode is trying to link this control to the outlet on the view controller, but this outlet doesn't exists (because you are allocating an UIViewController not the subclass).

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

Calling View from Class

I think I have a simple issue with my app.
First of all I am using the PraseSDK in order to use the LoginView they offer.
Now I was going to create that function and let it called by a view controller in
-(void) viewDidLoad
It worked perfectly.
Now I was wondering if I can put that code into a global function class?
Well I created a Class called: glo_function
Inside of it I created a function which is call
+(void) CallLoginScreen{
PFLogInViewController *login = [[PFLogInViewController alloc] init];
login.fields = PFLogInFieldsUsernameAndPassword | PFLogInFieldsLogInButton;
[self presentModalViewController:login animated:NO];}
In My ViewController Iam using "callLoginScreen" like this
[glo_function CallLoginScreen]
The methode is going to be called by the View Controller but the view will not show up.
Well I get that error will trying to run the app.
No known class method for selector 'presentModalViewController:animated:'
So I am pretty sure It do to the fact that I used the "self" in->
[self presentModalViewController:login animated:NO]
Can someone help me out with it? should be easy, hopefully :)
-----------------------Response------------------------------
Hi after I did that, the app crashes.
The Call methode looks like that:
[glo_function showLoginScreenUsingViewController];
In glo_function.m the methode looks like that:
+ (void)showLoginScreenUsingViewController:(UIViewController *)VC {
PFLogInViewController *login = [[PFLogInViewController alloc] init];
login.fields = PFLogInFieldsUsernameAndPassword | PFLogInFieldsLogInButton;
[VC presentModalViewController:login animated:NO];}
The Result when starting the App:
2012-12-28 21:20:24.003 Logbuch40[1942:c07]
*** Terminating app due to uncaught exception 'NSInvalidArgumentException'
, reason: '+[glo_function showLoginScreenUsingViewController]:
unrecognized selector sent to class 0x22e9ec
"self" always refers to the object you are in. In your case it's the glo_function object. So when you say self you are talking to the wrong object.
You could still do what you want but in your glo_function method you need to pass in a reference to your view controller. Then just use that in your function instead of self.
+ (void)showLoginScreenUsingViewController:(UIViewController *)VC {
PFLogInViewController *login = [[PFLogInViewController alloc] init];
login.fields = PFLogInFieldsUsernameAndPassword | PFLogInFieldsLogInButton;
[VC presentModalViewController:login animated:NO];
}

iPhone SDK: Switching to one view then back to previous view errors

I have a UITabBarConroller that I use to switch between 3 different views. This all works perfectly. On one of my tabs, I added a button at the to called "Add", I have added an outlet to this, as well as an IBAction method which looks like the following:
// Method used to load up view where we can add a new ride
- (IBAction)showAddNewRideView {
MyRidesViewController *controller = [[MyRidesViewController alloc] initWithNibName:#"AddNewRide" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
[controller release];
}//end showAddNewRideView
This currently works fine, and loads up my AddNewRide nib file. But, once that view loads, I have a cancel button, which, when clicked, I want to return to the previous view. So, I figured I would just do the reverse of the above, using the following method which would load back my previous nib:
- (IBAction)cancelAddingNewRide {
MyRidesViewController *controller = [[MyRidesViewController alloc] initWithNibName:#"MainWindow" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:controller animated:YES];
[controller release];
}//end cancelAddingNewRide
But, which trying to load the MainWindow nib, the program crashes, and I get the following error:
2010-05-05 20:24:37.211 Ride[6032:207] *** -[MyRidesViewController cancelAddingNewRide]: unrecognized selector sent to instance 0x501e450
2010-05-05 20:24:37.213 Ride[6032:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[MyRidesViewController cancelAddingNewRide]: unrecognized selector sent to instance 0x501e450'
So, I am a little lost as to why it would work one way, but not the other.
First, I wanted to address part of the error: Think of your views as a stack. When you "push" a modal controller, you are adding that view to a stack. The old view is still there underneath. So you need to "pop" off the modal view to return to the old view. If you push a new view on, you now have 3 views on the stack which are all taking up memory, where you really only need one.
So, inside cancelAddingNewRide just try:
[super dismissModalViewControllerAnimated:true];
You may have other issues that are causing the crash, but this should generally get things working.
Typically when I have used presentModalViewController the presented viewController tells the calling viewController to dismiss it using dismissModalViewControllerAnimated:YES;
So in other words in the cacncelAddingNewRide you simply call the class that hass showAddnewRideView in it and have it pass itself to the method.
It's hard to explain but I'll show you an example:
cancelAddingNewRide class:
- (IBACtion)home:(id)sender {
if (self.delegate respondsToSelctor:#selector(dismiss:)]) {
[self.delegate dismiss:self];
}
}
and then in the showAddNewRideView class
-(void) dismiss:(cancelAddingNewRide_class *) controller {
[self dismissModalViewControllerAnimated:Yes];
}
Hope that makes sense and soz for typos
Edit: oh and make the controller's delegate self
controller.delegate = self;
Actually thinking about it more there is a bit more to this. You have to define the called viewController as a Delegate. Have a look at Stanford universities iPhone lectures, lecture 11 deals with this and is available from iTunesU.

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