I have a button that I'm creating in a UIViewController like so:
TOLoginButton* button = [[[TOLoginButton alloc] initWithFrame:CGRectMake(60,180,200,40)] autorelease];
[self.view addSubview:button];
The button is a UIControl and I'm trying to call another UIViewController from within the touchUpInside method, below is what I have but it doesn't work:
- (void)touchUpInside {
MyViewController *viewController = [[MyViewController alloc] init];
[super.view addSubview:viewController.view ];
}
I'm basically trying to call this viewController once my button is pressed.
So viewController1 has the button on it and once the button is pressed I want to do something like [viewController1.view addSubview:viewController2.view].
assuming the new UIViewController is full-screen, the more usual thing to do is
[self presentModalViewController:viewController animated:YES];
or if you're using a navigation controller
[self.navigationController pushViewController:viewController animated:YES];
Related
I have a UIButton in UIVIewController and I need to push it to the UIVIew when I press the button.But this gives me the warning of incompatible pointer type sending
how to do this
What I am doing this:
-(void)press{
displayView *disp=[[displayView alloc]init];
[self presentModalViewController:disp animated:No];
}
this gives me warning and crashes my application.
presentModalViewController accepts a UIViewController instance (not UIView). If you want to display a particular view, place it within a view controller first.
UIViewController *viewController = [[UIViewController alloc] init];
DisplayView *displayView = [[DisplayView alloc] init];
[viewController.view addSubview: displayView];
[self presentModalViewController:viewController animated:NO];
I would like to know a method for navigating from one page to another page onclick .I
have tried
[self.navigationController
pushViewController:self
.objectNewlist
animated:YES];
but it is showing the error
Incompatible pointer types sending 'newlistplist *' to parameter of type 'UIViewController *'
my main class file is a subclass of UIViewController
and the second class is a subclass of UITableViewController
can any one help me out with this problem?
You can use
UIViewController *yourViewController = [[YourViewControllerClass alloc] initWithNibName:#"<name of xib>" bundle:nil];
[self presentModalViewController:yourViewController animated:YES];
[yourViewController release];
In case the new view is also to be created programmatically, you can do that in the viewDidLoad method of YourViewControllerClass and change the initialization to
UIViewController *yourViewController = [[YourViewControllerClass alloc] init];
In YourViewController when you wish to come back to previous view on some button action you can use
[self dismissModalViewControllerAnimated:YES];
Another way that you can do is
UIViewController *yourViewController = [[YourViewControllerClass alloc] init];
[self addSubview:[yourViewController view]];
and to remove the view you can use
[self.view removeFromSuperview];
-(void)onClickButton
{
ViewControllerClass *objViewControllerClass = [ViewControllerClass alloc] init] ;
[self presentModalViewController:objViewControllerClass animated:YES];
[objViewControllerClass release];
}
objViewControllerClass (object of another class)
I have a subclass of TTMessageController which is (CommentViewController) and I have the following mapping
[map from:#"tt://postDetails/(initWithPostId:)/(anotherId:)" toViewController:[PostDetailsViewController class]];
[map from:#"tt://groupBoardAddComment/(initWithPostId:)/(anotherId:)" toModalViewController:[CommentViewController class]];
When I call CommentViewController from my PostDetailsViewController class, its keyboard does not appear, but when I call it from my other view controller class its keyboard appears,
even if I try to force to becomeFirstResponder its textEditor in all viewWillAppear, viewDidLoad and etc. methods of my CommentViewController, still I cannot make it appear.
hope for a reply, really need help with this, Thanks
the problem here is, i call the method when user begins edit in my textfield, instead of textfield i change it to a button with a selector to call and display the CommentViewController,
Instead of this
- (IBAction)textFieldDidBeginEditing:(id)sender {
CommentViewController *commentViewController = [[CommentViewController alloc] initWithPostId:self.postId groupId:self.groupId];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:commentViewController];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[commentViewController release];
}
I made a method to be called by a button as a selector
-(void) displayCommentView
CommentViewController *commentViewController = [[CommentViewController alloc] initWithPostId:self.postId groupId:self.groupId];
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:commentViewController];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
[commentViewController release];
I have a view with a UIView and a button. Pressing the button brings up a ModalViewController which is UIView with UITextField in it. I need to pass the string value of NSObject in the UIView to the ModalViewController as a string. On button click I call this:
-(void) editNote{
TextViewController * vc = [(TextViewController *)[TextViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
[self.navigationController presentModalViewController:nav animated:YES];
[vc release];
}
Normally, on row select we push the data using pushviewcontroller to the next view but after doing lot of google I cannot figure out how to pass the data using presentmodalviewcontroller.
You could add a property to TextViewController, then just use vc.object = myObject. Or you could make a new init method that takes some more information.
I have one issue with UInavigationcontroller
In my firstview i have button.If i click that button it should open tableview in secondview .If i click tableviewcell is connect to third view.it is second and thirdview used to the navigationbar
Please help in this issue.
in appDelegate create a navigationcontroller like this i am posting sample code
HomeScreen *homeScreenObject=[[HomeScreen alloc] initWithNibName:#"HomeScreen" bundle:nil];
self.navController =[[UINavigationController alloc] initWithRootViewController:homeScreenObject];
[homeScreenObject release];
[window addSubview:[navController view]];
// Override point for customization after application launch
[window makeKeyAndVisible];
navController is instance Variable declared in header file
UINavigationController *navController;
now on your firstviewcontroller create a IBAction and bound your button's touch down event with that action and use these lines in that method
ViewController *ViewControllerObject = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self.navigationController pushViewController:ViewControllerObject animated:YES];
[ViewControllerObject release];
so the viewController should have a tableView and on tableView's delegate method "didSelectRowAtIndexPath" use the above code for further navigation