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)
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 want to call this method:
- (void)getUserFriendTargetDialogRequest {
currentAPICall = kAPIFriendsForTargetDialogRequests;
[self apiGraphFriends];
}
from this conditional statement that's in another viewcontroller:
if (idx == 2) {
NSLog(#"you touched menu 2");
APICallsViewController *apiViewController = [APICallsViewController alloc];
[self.navigationController pushViewController:apiViewController animated:YES];
}
can anyone help with the syntax on this?
thanks so much
First, you probably also want to init your APICallsViewController via:
APICallsViewController *apiViewController = [[APICallsViewController alloc] initWithNibName:nil bundle:nil];
Then if that getUserFriend... is a method of APIViewController, you can do this:
[apiViewController getUserFriendTargetDialogRequest];
However, since you aren't passing any arguments in from your other view controller, you might consider calling it in the init method, or the viewDidLoad method of APICallsViewController.
OtherViewController *viewController = [[OtherViewController alloc]
init];
[viewController methodName];
[viewController release];
1>Just alloc the class in which the method is and then call it through object of that class.
ViewControllWithMethod *view=[ViewControllWithMethod alloc]]init];
[view getUserFriendTargetDialogRequest];
2>Instead of instance method you can make it as class method then you will be able to call it through className.getUserFriendTargetDialogRequest
I'm not sure how to do this. So I originally had a ViewController that had one .xib, with one main view. I present it like this:
DogViewController *dvc = [[DogViewController alloc] initWithNibName:#"DogViewController" bundle:nil];
dvc.modalPresentationStyle = UIModalPresentationFormSheet;
dvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:dvc animated:YES];
[dvc release];
So that works fine. However now from a button press in the DogViewController.xib, I want to dismiss the current form sheet, and show another form sheet with some additional questions before proceeding. So I started by adding another view to in my original .xib of DogViewController, then got stuck in the logic of how to dismiss the first one, and show the second one. I'm assuming I need some outlet to the new view in the same .xib, but from there I'm lost. Thanks.
The way to do this would be to set it up with a UINavigationController as Mathiew mentions. However, if you really want to transition between two views on one view controller, you can refer to this sample code from Apple:
http://developer.apple.com/library/ios/#samplecode/ViewTransitions/Introduction/Intro.html
The code uses ImageViews to demonstrate the effect but I don't see why you can't use views instead :)
You can add a view within the other view in front of all of the other objects and just use its hidden property to control whether it's shown or not.
Why don't you use a navigation controller in your modal view, create another xib and do a [self.navigationController pushViewController:secondViewController animated:YES];
If you have a good reason, you can set a second view outlet secondView and use code like
UIView* superview = [self.view superview];
[self.view removeFromSuperView];
[superview addSubview:self.secondView];
Very simple solution is to hold reference to MainViewController and call methods on it that swap between two view controllers.
Like this:
#implementation MainViewController
- (void)showDogViewController {
[self dismissModalViewControllerAnimated:YES];
DogViewController *dvc = [[DogViewController alloc] initWithNibName:#"DogViewController" bundle:nil];
dvc.modalPresentationStyle = UIModalPresentationFormSheet;
dvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
dvc.mainViewController = self;
[self presentModalViewController:dvc animated:YES];
[dvc release];
}
- (void)showCatViewController {
[self dismissModalViewControllerAnimated:YES];
CatViewController *cvc = [[CatViewController alloc] initWithNibName:#"CatViewController" bundle:nil];
cvc.modalPresentationStyle = UIModalPresentationFormSheet;
cvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
cvc.mainViewController = self;
[self presentModalViewController:cvc animated:YES];
[dvc release];
}
}
#end
#implementation DogViewController
- (void)showCatViewController {
[mainViewController showCatViewController]
}
#end
#implementation CatViewController
- (void)showDogViewController {
[mainViewController showDogViewController]
}
#end
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 use the following code to bring up a view
-(IBAction) openSomeView{
SomeView *sv = [[SomeView alloc]initWithNibName:#"SomeView" bundle:nil];
[self presentModalViewController:sv animated:NO];
[sv release];
}
How can I detect if this view has been created already and if so, then just show it now create a new object?
Thanks
first declare in #interface
SomeView *sv;
and the you can check it
-(IBAction) openSomeView{
if(sv==nil)
sv = [[SomeView alloc]initWithNibName:#"SomeView" bundle:nil];
[self presentModalViewController:sv animated:NO];
[sv release];
}
You cannot create more than one instance using this code, since you present modally the view controller.
Else, you'd probably keep a member variable in your class and check it against nil.
EDIT: or you can implement the 'Singleton' design pattern, if that's the meaning you search.
I have a couple of heavy-weight view controllers in my app. Right now I'm handling this situation as follows:
save MyViewController to appDelegate
in "openSomeView" method I'm checking if MyViewController was already created, if no - create it:
-(IBAction) openSomeView {
MyAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
if ( !appDelegate.myViewController ) {
appDelegate.myViewController = [[SomeViewController alloc] initWithNibName:#"SomeViewController"
bundle:nil];
}
[self presentModalViewController:appDelegate.myViewController animated:NO];
}