I was wondering how I can add an int to a bundle and pass it to the next view that I am calling.
What I am trying to do is click an item on a UITableView and that will call the next .m file and pass the int that pertains to a document that I will be looking up online. This document has a specific id and without passing it to the next view I will not be able to get the list that I need to compile and show on the next UITableView.
How are you displaying the next view? Can you not just add an instance variable to the view to be called?
View2 *view = [[View2 alloc] init]];
[view setSpecificId:myId];
display the view....
Related
Can anyone please tell me how to reload the view.In my program,it contain a tab view controller.There is one item named "A" in the tab.And this "A" item is pointing to a viewController.In that view Controller, it is displaying some datas and I have included UIActionSheet in that. There is one button-Delete in the actionsheet.This delete button is for deleting the particular data.Now my problem is that I need to reload that view so that these deleted data should not be displayed. So anyone please tell me how to reload the page. I have included the following code before
[self presentModalViewController:historyView animated:YES];
[historyView setNeedsDisplay];
but it is showing some error :-
No visible #interface for viewcontroller declares the selector 'setNeedsDisplay'
Please tell me the solution.. :(
UIViewController class doesn't have a method setNeedsDisplay. The UIView class does have this method. So you can write like that:
[historyView.view setNeedsDisplay];
But this method doesn't reload a view. It just marks the receiver’s entire bounds rectangle as needing to be redrawn (from apple documentation iOS Developer Library). So as a result the drawRect method will be called.
To solve your problem you can create your own function like initializeUI in your view controller and then call it when the view is loaded initially (in viewDidLoad method) and for example after deleting the data when you need the view to be updated.
So I have this UINavigationController, I'm on the first moving to the next view, than I want to hit the 'back' button and to go back to the first view with the data that I saved into 'strAddress' on the second view. I want to present the data on the first view on 'lblShowStr.text'.
how can I manage to do that? I've searched all the web, found some people that wrote, but couldn't understand what they have been told there.
Thanks!
You can get a reference to the previous viewController in your navigation stack by saying:
NSArray *viewControllers = self.navigationController.viewControllers;
MyViewControllerClass *previousController = [viewControllers objectAtIndex:[viewControllers count] - 2];
You can then set a property on the 'previous' view controller to store your text, or even set the label outlet's text directly like this:
previousController.lblShowStr.text = self.strAddress;
It's not the best way to do it (the best way involves creating a custom delegate protocol or using NSNotificationCenter) but it's the easiest way.
In your first view controller you might have an NSString property called strAddress.
and you put that string into lblShowStr.text every time the view appears.
In your second view controller you might have a property pointing to an instance of view controller one. When you instantiate your second view controller you could assign the property on it to the first view controller.
secondViewController.firstViewController = self;
or
[secondViewController setFirstViewController:self];
Then when the user presses the back button viewDidAppear would get called for the first view and update the string.
I am assuming you don't want to store this data anywhere else e.g. in your model or nsuserdefaults etc.
Trying to send some data form my previous ViewController. To be more clear trying to send the selected date of the Si-Calendar to my secondView.
I'm adding the Calendar to my view in this way:
CalendarMonth *aCalendarView = [[CalendarMonth alloc] initWithFrame:CGRectMake(0, 0, 320, 324) logic:calendarLogic];
[aCalendarView selectButtonForDate:selectedDate];
[self.view addSubview:aCalendarView];
How do I use selected date and send it to my secondViewController (a UIView in which I'll display the selected date)?
Add a date property to your secondViewController, and set it appropriately when you create the instance...
It is a bit unclear what the first or second viewController is, but in general you could use a delegate for this purpose. For an example on how to do this, take a look at this answer
There are many ways to exchange data between view controllers, just take them as objects.
first controller hold a ref of the second controller, and transfer data using variables and methods
use delegate,
use notification
etc.
i can see that you are adding the CalenderMonth as the subview to another view. So if you dont release it (until u create the second view controller), you can set the selectedDate of the calender month obj to an iVar of second view controller. Else Create a delegate for CalenderMonth class. Set the second view controller as the delegate of the CalenderMonth and do the necessary.
I have an application with 2 views . In the first one I have a button which when I clicked the user should go to the second view. I tried what is explained before here from Karoley , but it does not work . When I click the button nothing happened?
Here is the code of my action :
-(IBAction)gotoSecondPage:(id) sender{
NSLog(#"In gotoSecondPage");
LeoActionViewController *aSecondPageController =
[[LeoActionViewController alloc]
initWithNibName:#"LeoActionViewController"
bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:aSecondPageController animated:YES];
}
LeoActionViewCOntroller is a controler for a second view.
It just do not switch to a second view. I do not know why
I put code your problem this will help you. First of all, you declare method and open .xib file and then connect to that button with selected touchupinside connection.
In the .h file:
- (IBAction)gotoSecondPage:(id) sender;
In the .m file:
- (IBAction)gotoSecondPage:(id) sender
{
NSLog(#"In gotoSecondPage");
LeoActionViewController *aSecondPageController =
[[LeoActionViewController alloc]
initWithNibName:#"LeoActionViewController"
bundle:nil];
[self.navigationController pushViewController:aSecondPageController animated:YES];
[aSecondPageController release];
}
I'm not sure in what capacity you want to switch views.
What immediately comes to mind is that you want a Navigation Controller. This is an object that lets you put view controllers on a stack and push and pop them to show and hide them. It creates a navigation pathway through your app and is easy to use. It also facilitates the 'standard' navigation bar which is found in many iphone apps.
If you just want to change one view for another view you can do many things including hiding and showing different views using setHidden:(bool)hidden. Otherwise you can use addSubview:(UIView *)view and removeFromSuperview to add and remove views completely from the superview.
how would an add to favorites button work in order to take the controller selected and add it to a tab bar item,
i tried using an ibaction to add an entry to an array however i wasnt sure on how to handle this problem.
i would like to add a uibutton that adds an entry to this kind of array format
rootArray = [[NSArray alloc] initWithObjects:#"entry1", #"entry2", nil];
the tab bar would have two views on the favorite table view and one with all the rest of the cells. i would like to click on the "normal" table view which would take me to the detailview controller already implemented. Afterwards i would like to have a button on the detailviewcontroller that would say something like add to favorites and add this detailview and its cell to the favorites tab controller. i would like to add the uibutton to add the detailview controller in the mentioned format above however im not sure how to do this.
i would appreciate some help in pointing me in the right direction thanks
Am assuming u have a database somewhere from where you are getting data for your "normal" tableview. What you need to do is you could add a favorites table or just add a "is_favorite" field to your table.I'd go with the latter option.
With this in place you just have to filter your results. Records with "is_favorite" as true added to the favorites table view while everything (both favorite and non-favorite) appear in the other table view.
For the details view, you could have a UIBarButton for adding to favorites. The iphone sdk already has a system button for that. Add the following to you viewDidLoad:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemBookmarks target:self action:#selector(addToFavorites:)];
then add a method called addToFavorites to your detailviewcontroller class. This will respond to the IBAction. Inside addToFavorites add some code that will set the is_favorite field to true.
I believe all this covers how you could accomplish your task.
Edit: The explanation above was based on the assumption you were using a database.
Update
Since you are storing everything in an array here's what you could do.
Define the favorites (mutable)array in you YourAppDelegate.h file as you would any normal property.
NSMutableArray *favorites;
Then inside the addToFavorites do something like:
YourAppDelegate *app = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
[app.favorites addObject:current_detail]; //add whatever detail you selected
favorites is the array you will be using as the source of data for your favorites table view.
Hope all this makes sense now.