I have a simple application and I require a bit of assistance with one new feature.
The application is a table view (TV1) which is populated by the user adding an entry (a button in the navigation bar which modally brings up a new view controller for the user filling in a name, event and amount text field and selecting a date from the date picker).
The table view controller is part of a tab bar controller where the first tab shows everything (timeline) and the second tab shows just the list of events. If you click on an event, you segue over to see all transactions with that event.
I've added a bar button item here as well which segues to the Add Entry view controller, with the aim of having the event already selected.
What I mean by this is:
Say you have 3 events called Wedding, Birthday and Anniversary in your transactions. If you click on the Event tab, you'll see Wedding, Birthday and Anniversary in a Table view. Clicking Birthday will show you all the transactions where event = Birthday.
I have a bar button item which will allow me to add entries from this screen, but because it's coming from the Birthday event, I want that event text field to already be filled in, in the Add Entry with the name of this event (Birthday in this case).
I'm using Core Data and NSFetchedResultsController.
The situation right now is, when I press the button to add a new entry from the Selected Event (Birthday), it's not pre-configuring the event text field with Birthday in the Add Entry screen.
Here's some code which should hopefully explain what I'm doing.
From the Event Tab
// This segues over to the selected event (Birthday).
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = [self.eventTableView indexPathForCell:sender];
Occasion *selectedOccasion = [self.fetchedResultsController objectAtIndexPath:indexPath];
if ([segue.identifier isEqualToString:#"Selected Occasion Segue"])
{
ESelectedOccasionTableViewController *selectedOccasionTVC = [segue destinationViewController];
[selectedOccasionTVC setOccasion:selectedOccasion];
}
}
From the Selected Event Tab (Birthday), I create two segues, one for editing a cell and one for creating a new entry:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = [self.selectedOccasionTableView indexPathForCell:sender];
Transaction *seletedTransaction = [self.fetchedResultsController objectAtIndexPath:indexPath];
// The first segue is to "edit" the existing entry
if ([segue.identifier isEqualToString:#"Editable Cell"])
{
EDetailViewController *dvc = (EDetailViewController *)segue.destinationViewController;
dvc.selectedTransaction = seletedTransaction;
}
// This segue is to create a new entry from the event
else if ([segue.identifier isEqualToString:#"Create New Entry From Event"])
{
EddEntryViewController *eAppEntryViewController = (EAddEntryViewController *)segue.destinationViewController;
[eAppEntryViewController setSelectedTransaction:selectedTransaction];
}
}
The first segue is for editing the cell (which works perfectly), but in the second segue, the one I'm interested in here, I'm not actually clicking on a cell; I'm clicking on a bar button item which will modally bring up the add entry. I want to take just the "event" (Birthday) from this Table View and pre-fill the "event text field" in the Add Entry.
The setSelectedTransaction in the Add Entry is:
- (void)setSelectedTransaction:(Transaction *)selectedTransaction
{
_selectedTransaction = selectedTransaction;
self.occasionTextField.text = _selectedTransaction.occasion.title;
}
I can't imagine I'm very far from getting this working, but any assistance on this would really be great because I'm really stuck.
Should I be setting something in viewDidLoad? (That did not work either).
I'm not selecting a table view cell which is why I understand that the [eAppEntryViewController setSelectedTransaction:selectedTransaction]; line isn't actually passing anything, because I'm clicking on a bar button item, not a table view cell.
The model is: a Transaction Entity that links to the Date and Event Entities.
I have resolved this issue in the following way:
EAddEntryViewController *eAppEntryViewController = (EAddEntryViewController *)segue.destinationViewController;
[eAppEntryViewController setSelectedEvent:self.occasion.title];
Which called:
- (void)setSelectedEvent:(NSString *)selectedEvent
{
_selectedEvent = selectedEvent;
}
In the viewWillAppear, I did:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.occasionTextField.text = self.selectedEvent;
}
This works the way it is and I'm happy with this.
So I might not be understanding the question fully. But you can add a "Touch Up Inside" event to the bar button item and then pull the text from the "sender" object. Then, either store that text as an NSString property in the interface for later use, or set your desired textbox straight from the bar button item action.
Related
can't for the life of me figure this out.
so I'm creating a contact list app, very similar to the one that comes with iOS7.
a user creates a name with the GUI on a detail view controller.
user goes back to the main contact list page (master view controller)
user taps on the name/contact they just created
brings them back to the view controller, but it shows what they had entered into the text fields.
User starts with this screen:
User hits the add contact button, adds in the user data here which brings them back to the first screen:
Next, they are brought to the first screen and are able to tap on the contact they've added and should bring up all the details entered (firstname,lastname,phone number etc):
here's my code in my master view controller:
- (void) detailViewControllerWillDissapear: (DetailViewController *) dvc {
NSLog(#"test");
DirectoryEntry *person = [[DirectoryEntry alloc] init];
person.firstName = dvc.txtFirstName.text;
person.lastName = dvc.txtLastName.text;
person.phoneNumber = dvc.txtPhoneNumber.text;
person.address = dvc.txtAddress.text;
[self.entries addObject:person];
NSLog(#"index is %#", person.firstName);
NSLog(#"count of array %lu", (unsigned long)self.entries.count);
dvc.holdData = person;
[self.tableView reloadData];
}
here's my segue:
#pragma mark - segue
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
//DirectoryEntry *person = [[DirectoryEntry alloc] init];
DetailViewController *dvc = segue.destinationViewController;
dvc.delegate = self;
if ([segue.identifier isEqualToString:(#"tappedData")]) {
NSLog(#"what is the person class have %#", dvc.holdData);
// NSLog(#"dvc.holdData = %#", person.firstName);
}
}
so I've created the public variable holdData which is meant to hold all the data which was entered from the array into the Person class. but whenever I add it, just comes up with a Null value. I am able to access the variables i.e. holdData.firstName, but just everything is null.
any ideas? really confused, thanks.
The dvc that you have in prepareForSegue is almost certainly not the same object that you had in the detailViewControllerWillDissapear method. (Try printing their addresses to prove that for yourself.) That means that either your main controller should save the Person data and provide it during the segue or you could create a separate data model that each DetailViewController would use directly.
Are you able to edit images with QLPreviewController?
For example, preview an image and crop it? If not, what is the editing property on QLPreviewController for? It doesn't seem to change anything. (Previewing files is working fine)
Here is an example:
QLPreviewController *previewController=[[QLPreviewController alloc]init];
previewController.delegate=self;
previewController.dataSource=self;
[previewController setCurrentPreviewItemIndex:selectedIndex];
[previewController setEditing:YES animated:YES];
[self presentModalViewController:previewController animated:YES];
Delegate methods:
- (id <QLPreviewItem>)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index
{
file = [folder.files objectAtIndex:index];
controller.title = file.name;
CustomQLPreviewItem *customQLPreviewItem = [[CustomQLPreviewItem alloc] init];
customQLPreviewItem.previewItemURL = [NSURL fileURLWithPath:file.uri];
customQLPreviewItem.previewItemTitle = file.name;
return customQLPreviewItem;
}
- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller
{
return folder.file.count;
}
QLPreviewController does not support editing in the way you are thinking.
the editing property is actually inherited from UIViewController and from here:
UIViewController Class Reference
editing A Boolean value indicating whether the view controller
currently allows the user to edit the view contents.
#property(nonatomic, getter=isEditing) BOOL editing Discussion If YES,
the view controller currently allows editing; otherwise, NO.
If the view is editable and the associated navigation controller
contains an edit-done button, then a Done button is displayed;
otherwise, an Edit button is displayed. Clicking either button toggles
the state of this property. Add an edit-done button by setting the
custom left or right view of the navigation item to the value returned
by the editButtonItem method. Set the editing property to the initial
state of your view. Use the setEditing:animated: method as an action
method to animate the transition of this state if the view is already
displayed.
Availability Available in iOS 2.0 and later. See Also –
setEditing:animated: – editButtonItem Related Sample Code BonjourWeb
iPhoneCoreDataRecipes Declared In UIViewController.h
I am using a uipopover to present a mini number pad to the user when they enter a textfield on my main view controller.
when they enter numbers using the number pad, i save the entry into a nsstring property that I've named keypadvalue.
there is an unwind segue wired to a done button on the popover which fires the following code.
- (IBAction)doneWithKeyboard:(UIStoryboardSegue *)segue
{
NSLog(#"unwind");
if ([segue.sourceViewController isKindOfClass:[KeyPopupViewController class]])
{
KeyPopupViewController *popOver2 = segue.sourceViewController;
activeField.text =popOver2.keypadValue;
}
}
the activetextfield on my main view controller then gets updated to the kepadvalue, and this all works fine.
my problem now is that i want the activetextfield to update the same way if the user presses outside the uipopover, and it dismisses without firing the unwind segue.
i thought i might use the following to perform the update when the popover dismisses
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
activeField.text = controller.keypadValue;
return YES;
}
unfortunately despite multiple attempts i can't get the property to return a value it is always null even though the method fires as expected.
how should i recover the property value from the popover using this or another method?
i am obviously doing something wrong
can anyone advise
thanks
It should help:
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
[self.view endEditing:YES];
activeField.text = controller.keypadValue;
return YES;
}
In this case, I am assigning values below to stringToDisplay and want to send them to SegViewController, which also retains stringToDisplay. Do I need to use cell.textLabel.text here with isEqualToString: #"Fire House Gallery? Would I use indexPath or UITableViewCell here?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
SegViewController *seg = segue.destinationViewController;
seg.delegate = (id)self;
if ("......" isEqualToString: #"Firehouse Gallery"])
{
seg.stringToDisplay = #"Firehouse Gallery";
}
else
{
seg.stringToDisplay = #"Frog Hollow Craft Center";
}
}
Thank you,
Greg
The short answer:
You shouldn't derive data from your table view cells because they are your view. You should be "deriving data" from your model.
The longer answer:
Determining how to configure your segue depends on how you are calling it:
If you are calling it in code (using performSegueWithIdentifier:sender) then pass your string as the "sender" in your method call.
If you have setup the segue in your storyboard, then you should use different segues for each possibility, and check the segue identifier to determine which string that you should pass.
I found an answer for what I was looking for. I now have ONE segue link between two UIViewcontrollers, with the segue identifier called #"seg". For a place named Radio Bean, I use the following when the "Radio Bean" cell is pressed:
if ([cell.textLabel.text isEqualToString: #"Radio Bean"])
{
self.stringToDisplay = #"Radio Bean";
[self performSegueWithIdentifier:#"seg" sender:self];
}
Then, in prepareForSegue I DO NOT specify segue identifier but use the following:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
SegViewController *seg = segue.destinationViewController;
seg.delegate = (id)self;
if ([self.stringToDisplay isEqualToString: #"Radio Bean"])
{
seg.stringToDisplay = #"Radio Bean";
}
}
This successfully passes "Radio Bean" to the next UIViewcontroller, and I can include multiple place options with the use of only ONE segue link, so, no need for multiple links.
I have an CustomUIScrollView that have many CustomUIButton inside (each button is a news item that have an image and title --> each button have a news ID
When touch inside button, the touchupInside event fire --> everything is OK
But i want when touch in button, a detail news Page, detailViewController, will create and push into navigationController (like BBC NEWS app in Store) and the detail Page will load webpage has ID equal with ID of Button we has touched.
My tableviewController is rootViewController, how can I pass event with ID data from Button in Scrollview inside UITableViewCell to my rootviewController to push a new DetailViewController
Thank in advance. (See picture make more easy to understand)
enter code hereHi i used this code try this..
in this code i pass button tag form calling method and compare to called method and then take your action whatever you need.
Thank You
-(IBAction)btnpress:(id)sender
{
UIButton *btn = (UIButton *)sender;
NSLog(#"%d",btn.tag);
if(img_alphabet.tag == btn.tag)
{
}
}