Cannot get Twitter-OAuth-iPhone to work - objective-c

demo works as expected, no problems. But now I'm trying to integrate it into my project. I use no xib-s, code only:
OAuthTwitterDemoViewController *vc = [[OAuthTwitterDemoViewController alloc] init];
[[UIApplication sharedApplication].keyWindow addSubview:vc.view];
[vc release];
it compiles and runs with no errors, but the actual OAuthTwitterDemoViewController is never visible. I've also tried it from a custom viewController with [self.view addSubview:vc.view]
What's the secret??
Update:
OK, here's what I did with NavigationController:
TwitterAuthViewController *vc = [[TwitterAuthViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc];
[vc release];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];

OK, the problems seems to be that I called [self presentModalViewController: controller animated: YES] from ModalViewController->NavigationController. That's where Cocoa touch OR Twitter-OAuth-iPhone (I don't really know which one exactly) have a problem. But this is how I need it.
Solution would be, as Ben already said, simply to push SA_OAuthTwitterController like [self.navigationController pushViewController:controller animated: YES];.
The only remaining problem is that SA_OAuthTwitterController internally creates own NavigationController bar, so that now I have 2 navigation bars visible.

Related

How to drill down and show detail uitableview with splitview without storyboard

I implemented a splitview using 2 UITableViews and a UIViewController. Showing both on the screen with their own data is working fine.
Now in my DidSelectRowForIndexPath I did the following:
DetailViewController *nextController = [[DetailViewController alloc] initWithStyle:UITableViewStylePlain];
NSMutableArray *objects;
objects = [[NSMutableArray alloc] initWithObjects:#"A", #"B", nil];
nextController.title = #"Filter";
[nextController SetArray:objects];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:nextController];
[self presentModalViewController:nc animated:YES];
//used this before [self.navigationController pushViewController:nextController animated:YES];
[FilterView deselectRowAtIndexPath:indexPath animated:YES];
Maybe you know a better method as what I did to present the nextController
The nextController is always showing up from the bottom and moving to the top. How can I accomplish this default sliding animation where the detail view comes into the view from the right side?
If you have started the app from the master/detail template while creating the project. Then it will have the navigation controller set automatically in the appDelegate didFinishLaunching method so in the didSelect methods you have to just use
`[self.navigationController pushViewController:vc animated:YES];`
instead of
[self presentModalViewController:nc animated:YES];
Here is a sample code which uses split view with navigation to and from root view.
First you need to confirm that you have UINavigationController at base then you can pushViewController:nextController
[FilterView deselectRowAtIndexPath:indexPath animated:YES];
DetailViewController *nextController = [[DetailViewController alloc] initWithStyle:UITableViewStylePlain];
NSMutableArray *objects;
objects = [[NSMutableArray alloc] initWithObjects:#"A", #"B", nil];
nextController.title = #"Filter";
[nextController SetArray:objects];
[self.navigationController pushViewController:nextController animated:YES];

Pushing UIViewController in navigationcontroller shows empty view

I am facing the problem that when I push my viewcontroller in the navigationcontroller all it does is changing the navigationbar and showing the standard background but no view is to be seen. My code for pushing the viewcontroller into the navigationcontroller looks like:
Viewcontroller1 *viewController = [[Viewcontroller1 alloc] autorelease];
[[self navigationController] pushViewController:viewController animated:YES];
But, if I initialise the viewcontroller by creating IBOutlets for it, it works just fine. But the reason why I am not doing that is because I later on needs to pass some parameters to the class on initialization.
Thanks for your time.
You have to initialise your view like
if you have xib then
Viewcontroller1 *viewController = [[[Viewcontroller1 alloc] initWithNibName:#"Viewcontroller1" bundle:nil]autorelease];
[[self navigationController] pushViewController:viewController animated:YES];
if you haven't xib
Viewcontroller1 *viewController = [[[Viewcontroller1 alloc] init]autorelease];
[[self navigationController] pushViewController:viewController animated:YES];

ModalViewController with embedded nav controller - Unable to dismiss

I present a modalViewController that is actually a navigation controller with one view, and a custom navigation bar. The modal view appears fine as expected, but when I attempt to remove it from view using [self dismissModalViewControllerAnimated:YES], I am hitting a "-[UINavigationController modalViewController]: message sent to deallocated instance". Can't seem to figure this out. Any ideas?
Instantiating the ModalViewController:
// Make a navigation controller and add the view inside it
MyViewController *evc=[[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
//UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:evc];
UINib *nib = [UINib nibWithNibName:#"UINavigationBarWithBackgroundImage" bundle:nil];
UINavigationController *nvc = [[nib instantiateWithOwner:nil options:nil] objectAtIndex:0];
[nvc setViewControllers:[NSArray arrayWithObject:evc]];
evc.delegate=self;
[evc release];
[self presentModalViewController:nvc animated:YES];
[nvc release];
and trying to remove it. This is where the error comes in:
[self dismissModalViewControllerAnimated:YES];
Not sure about this, but try it anyway:
Remove
[nvc release]
and see if
[self dismissModalViewControllerAnimated:YES];
now works.
Is there a reason you are loading two seperate nibs to show this modal? You do not need to load a nib containing a navigation controller to get this working.
Try something like this:
// Make a navigation controller and add the view inside it
MyViewController *evc= [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:evc];
evc.delegate=self;
[self presentModalViewController:navController animated:YES];
[evc release];
[navController release];

Close UIViewController

I'm trying to close soon after a UIViewController call another. It should be simple, but I'm not succeeding. I am using the following method:
- (IBAction)bClose:(id)sender {
iTest *test = [[iTest alloc] initWithNibName:#"iTest" bundle:[NSBundle mainBundle]];
test.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:test animated:YES];
[test release];
[self dismissModalViewControllerAnimated:YES];
}
I believe it's not simple. I have done something similar but instead I present the second in the first, then dismiss the first when the second wants to dismiss (dismissing both at the same time). To explain what I mean better:
main -> present controller1
controller1 -> present controller2
controller2 -> dismiss controller1
I'm sure there is a better solution to it though.
Something like this:
inside first controller:
UIViewController *c1 = [[UIViewController alloc] init];
[self presentModalViewController: c1 animated:YES];
inside c1:
UIViewController *c2 = [[UIViewController alloc] init];
c2.c1 = self;
[self presentModalViewController: c2 animated:YES];
inside c2:
[c1 dismissModalViewControllerAnimated:YES];
i also had to try something similar..but ran into much of the same problem..
My solution was to initiate a timer with time 0.5 sec and then dismiss the view in the selector
Worked for me.

Why does self.navigationController become nil?

I have this code:
ViewController2 *childView = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
[self.navigationController pushViewController:childView animated:YES];
I the first line, self.navigationController has a value.
On the second line, its value becomes 0. Why is that?
Unless you have overridden initWithNibName:bundle: in ViewController2 to do something truly unfortunate, there's extremely little chance that what you're saying can be true.
If you alter your code with this following assertion, does the assertion really trigger?
UINavigationController* navigationController = self.navigationController;
ViewController2 *childView = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
NSAssert(navigationController == self.navigationController, #"I was removed from the navigation controller!");
[self.navigationController pushViewController:childView animated:YES];