What CallOut have I pressed? - objective-c

If I have many Annotation in my map view… how to understand what CallOut I've pressed? In tableview for example we have "didSelectRowAtIndexPath"... but here?
-(void)button:(id)sender {
[self performSegueWithIdentifier: #"dettaglio"sender: self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if (![[segue identifier] isEqualToString:#"dettaglio"]&&![[segue identifier]
isEqualToString:#"cerca"])
{
[(paginaOpzioni*)segue.destinationViewController setDelegate:self];
}
if ([[segue identifier] isEqualToString:#"dettaglio"])
{
paginaDettaglio *ibcVC = [segue destinationViewController];
Annotazione *annotazioneDaPassare=[mapAnnotations objectAtIndex:2];
ibcVC.immagine = annotazioneDaPassare.immagine;
ibcVC.navigationItem.title = annotazioneDaPassare.title;
}
}
I need to change the value (2) of [mapAnnotations objectAtIndex:2]; because I want to send to the DestinationViewController the right image and text! Thanks

Your MKMapViewDelegate will tell you what was selected when it calls -mapView:didSelectAnnotationView:
http://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/intfm/MKMapViewDelegate/mapView:didSelectAnnotationView:
Unless of course you were referring to the accessory being tapped. That would be -mapView:annotationView:calloutAccessoryTapped:
http://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapViewDelegate_Protocol/MKMapViewDelegate/MKMapViewDelegate.html#//apple_ref/occ/intfm/MKMapViewDelegate/mapView:annotationView:calloutAccessoryControlTapped:

Related

get method parameters on prepareForSegue

I have a method that gets the data(specifiers and title) from that row and i after segue.
- (void)yd_deleteViewControllerWithTargetTypeSpecifiable:(id<YDTargetTypeSpecifiable>)specifier
title:(NSString *)title
onClose:(void(^)(void))onCloseBlock
{
NSLog(#"%#/%#", title, specifier.target_id);
[self performSegueWithIdentifier:SEUGE_GO_DELETE sender:self];
}
How can i pass that parameter from prepareForSegue?
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:SEUGE_GO_DELETE]) {
// Get destination view
YDDeleteViewController *makeDC = (YDDeleteViewController*)segue.destinationViewController;
// Pass the information to your destination view
makeDC.labelname = #"title";
}
}
Store the info you need in ivars (properties):
NSLog(#"%#/%#", title, specifier.target_id);
[self setTitleInfo:title];
[self setSpecifierInfo:specifier];
[self performSegueWithIdentifier:SEUGE_GO_DELETE sender:self];
Then in prepareForSegue you pick them up:
YDDeleteViewController *makeDC = (YDDeleteViewController*)segue.destinationViewController;
// pick up [self titleInfo] and pass it along to makeDC
// pick up [self specifierInfo] and pass it along to makeDC

How to set destination view controller using indexpath value?

I have a collection view controller if the user select any cell means its need to go destination view controller.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
cell=[collectionview cellForItemAtIndexPath:indexNumberStorager];
NSInteger indexnum;
indexnum=indexNumberStorager.row;
switch (indexnum) {
case 1:
if ([segue.identifier isEqualToString:#"Car"])
{
CarCleaningVC *dest = [segue destinationViewController];
}
break;
default:
break;
}
i tried using this code but not working properly please help me to find out the problem.
sender here is the cell that has been selected by the user (if the segue is on cell selection). You don't need to store indexPath anywhere.
Simply typecast sender into UICollectionViewCell(or your subclass if you're using any), and call indexPathForCell: on your collection view to get the indexPath.
Sample code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSUInteger indexNum = [self.collectionView indexPathForCell:(UICollectionViewCell*)sender].row;
switch (indexNum)
// Relevant code
}
Also, instead of depending on the segue identifier, try to use the destinationViewController's class:
if ([segue.destinationViewController isKindOfClass:[CarCleaningVC class]]) {
//relevant code
}
You can do something like this-
in your cellForItemAtIndexPath method, set the cell tag. Something like-
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
cell.tag=indexPath.row;
return cell;
}
And then when you cast your sender to a cell, you can just access its tag which is your Collection View's Indexpath.row.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UICollectionViewCell *cell=(UICollectionViewCell*)sender;
NSInteger indexnum;
indexnum=cell.tag;
switch (indexnum) {
case 1:
if ([segue.identifier isEqualToString:#"Car"])
{
CarCleaningVC *dest = [segue destinationViewController];
}
break;
default:
break;
}

How to get the selected section in a UITableView

I have a HistoryTableViewController with 2 sections hooked up to a detail view controller. I want to be able to display the text and subtitle text from the HistoryTableViewController in the details view, but I want to make sure that it detects the right section. I know somewhere along the line I'll have this:
if (section == 0)
{
labelCellNum.text = Whatever was the main text in the selected table view cell
labelDueDate.text = Whatever was in the subtitle text in the selected table view cell
}
else if (section == 1)
{
labelCellNum.text = Whatever was the main text in the selected table view cell
labelDueDate.text = Whatever was in the subtitle text in the selected table view cell
}
Since I'm displaying this on a details view controller, I don't know how to get the section from the TableViewController I'm getting displayed from. I pretty much need to know how to get the section, and the main text + subtitle text.
OK Perhaps I wasn't clear enough. This code is going in my ViewDidLoad of my DetailsViewController. NOT in my tableviewcontroller.
Here is the HistoryTableviewController code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// HistoryDetailsViewController *HDV = [self.storyboard instantiateViewControllerWithIdentifier:#"HistoryDetails"];
// [self.navigationController pushViewController:HDV animated:YES];
NSLog(#"index path section--%i",[indexPath section]);
[self performSegueWithIdentifier:#"Push" sender:indexPath];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:#"Push"]) {
HistoryDetailsViewController *detailVC=(HistoryDetailsViewController*)segue.destinationViewController;
detailVC.labelCellNum.text = #"Cell test";
detailVC.labelDueDate.text = #"Date Test";
}
}
And below is the code of my detailsViewController:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
labelCellNum.text = #"This isnt even getting called.";
}
check this , its simple
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(#"index path section--%i",[indexPath section]);
[self performSegueWithIdentifier:#"Push" sender:indexPath];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:#"Push"]) {
DetailViewController *detailVC=(DetailViewController*)segue.destinationViewController;
detailVC.title=#"value to pass";
}
}
There you go!
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Selected item infos
//
int section = indexPath.section;
int row = indexPath.row;
NSLog(#"section: %d / row: %d", section, row);
}
I assume you have a segue from the HistoryVC to the details VC. So you can pass the data across to the details VC in the prepareForSegue method in the HistoryVC. In the code fragment below, I am passing the cell title over into the new VC to set it's title. You could set other properties in the target VC, to suit your needs.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// get selected row's cell
//
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
// set desitination VC title
//
UIViewController *vc = [segue destinationViewController];
vc.navigationItem.title = cell.textLabel.text;
}

Retrieving UITableViewCell Label Values For Passing To Modal Edit View

I am trying to pass existing attribute values for a managed object, to a modal segue view for editing. From "editing mode," I'm going from a UITableViewController subclass (BreadRackTableViewController), using a modal segue to a UIViewController subclass (EditBreadRackTableViewController) by means of an embedded UINavigationController. Normal TableViewCell selection pushes to another UITableViewController subclass, but that's not important for the time being.
I've added properties to my editing view controller header (and #synthesized), to function as getters:
#property (nonatomic, strong) id existingBreadRackDataName;
#property (nonatomic, strong) id existingBreadRackDataDetails;
What I'm trying to do is populate the edit view's fields with the existing Core Data Entity Attributes, which would have been previously set by the user (in theory). I can get the data to show up if I pass along a literal string value, but I need to retrieve and pass the existing data.
Here's what I have currently:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"editBreadRackSegue"])
{
EditBreadRackTableViewController *ebrtvc = (EditBreadRackTableViewController *)[segue destinationViewController];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
BreadRackClass *breadRackClass = [[self fetchedResultsController]objectAtIndexPath:indexPath];
// [ebrtvc setBreadRackClass:breadRackClass];
ebrtvc.existingBreadRackDataName = breadRackClass.breadRackDataName;
ebrtvc.existingBreadRackDataDetails = [breadRackClass valueForKey:#"breadRackDataDetails"];
}
}
These last two lines of code...
ebrtvc.existingBreadRackDataName = breadRackClass.breadRackDataName;
ebrtvc.existingBreadRackDataDetails = [breadRackClass valueForKey:#"breadRackDataDetails"];
...they both return nil. If I specify a literal string though, that literal string shows up where it needs to.
All of that said, my question is:
How do I retrieve the attribute's key value for that selected row (or just the textLabel and detailTextLabels), and assign it to my setter?
Solution:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"editBreadRackSegue"])
{
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
BreadRackClass *breadRackClass = [[self fetchedResultsController]objectAtIndexPath:indexPath];
[segue.destinationViewController setExistingBreadRackDataName:[breadRackClass valueForKey:#"breadRackDataName"]];
[segue.destinationViewController setExistingBreadRackDataDetails:[breadRackClass valueForKey:#"breadRackDataDetails"]];
}
// code for other segues here...
}
I ended up removing the ebrtv variable, and cleaned up the code a little bit. What worked though, was using the indexPathForCell:sender instead of indexPathForSelectedRow when declaring my indexPath for breadRackClass.
I think the indexPathForSelectedRow could be a problem.
You can just pass the indexPath from the didSelectRowAtIndexPath to the prepareForSegue , like:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"editBreadRackSegue" sender:indexPath];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"editBreadRackSegue"])
{
NSIndexPath *clickedIndexPath = (NSIndexPath*)sender;
if( [clickedIndexPath isKindOfClass:[NSIndexPath class]] ){
BreadRackClass *breadRackClass = [[self fetchedResultsController]objectAtIndexPath:clickedIndexPath];
EditBreadRackTableViewController *ebrtvc = (EditBreadRackTableViewController *)[segue destinationViewController];
ebrtvc.existingBreadRackDataName = breadRackClass.breadRackDataName;
ebrtvc.existingBreadRackDataDetails = [breadRackClass valueForKey:#"breadRackDataDetails"];
}
}
}
Let me know if it works for you.

How do I call the following method from this IBAction?

How do I call the following method from this IBAction? I want to call the prepareForSegue: method instead of the NSLog(#"clicked");
Here's the IBAction:
- (IBAction) annotationViewClick:(id) sender {
NSLog(#"clicked");
}
Here's the method:
// Do some customisation of our new view when a table item has been selected
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure we're referring to the correct segue
if ([[segue identifier] isEqualToString:#"ShowMoreInfo"]) {
// Get reference to the destination view controller
MoreDetailViewController *mdvc = [segue destinationViewController];
[mdvc setSelectedItemName:[NSString stringWithFormat:#"%#", placeName.text]];
[mdvc setSelectedItemAddress:[NSString stringWithFormat:#"%#", placeFormattedAddress.text]];
[mdvc setSelectedItemWeb:[NSString stringWithFormat:#"%#", placeWebsite.text]];
[mdvc setSelectedItemRating:[NSString stringWithFormat:#"%#", placeRating.text]];
// [mdvc setSelectedItemDistance:[NSString stringWithFormat:#"%#", placeDistance.text]];
}
}
thanks for the help!
prepareForSegue: method calls automatically when you performing a segue.
To perform a segue you should use performSegueWithIdentifier:,
for ex. [self performSegueWithIdentifier:#"showGuide" sender:self];,
in this case you need assign identifier to a segue in Xcode Interface Builder.
id try something like
UIStoryBoardSegue *segue = ... setup the one you want
[self performSelector:#selector(prepareForSegue:) withObject:seque afterDelay:0];
ive never worked with storyboards - but thats how you call a selector :)