Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-14-2010, 03:55 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 3
tmoney11 is on a distinguished road
Default Passing an NSString Value to another view Controller

So in one view, I have a button the pushes another viewController with a map. The map let's the user select any location and provides an annotation with the reverseGeocode address of that location. The annotation has a button that 'pops' the view controller. Now when that button is pressed, I want it to update a label on the original view. How can this be done?

View 1 with button and label:
Code:
- (IBAction) pickLocation {
	
	MapViewController *mapcontroller = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];

	mapcontroller.navigationItem.title = @"Pick Location";

	[self.navigationController pushViewController:mapcontroller animated:YES];

	[mapcontroller release];

}
View 2 with Map and annotation:
Code:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
	if ([control isKindOfClass:[UIButton class]]) {		
		
      View1Controller *view1 = [[ View1Controller alloc] init];
			view1._address = address; //  'address' is synthesized in view2
			[view1 release];
	
						
		[self.navigationController popViewControllerAnimated:YES];

	}
}


- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)newPlacemark {
	
	
	for (DDAnnotation *annotation in _annotations) {
		if (annotation.coordinate.latitude == geocoder.coordinate.latitude && annotation.coordinate.longitude == geocoder.coordinate.longitude) {
			annotation.subtitle = [[newPlacemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
			
			address = [NSString stringWithFormat:@"%@", annotation.subtitle]; // 'address' is synthesized properly
	
			
			}

	}
}

The issue is the label ends up being null. How do I ensure the 'address' value from view2 gets stored as a string in view1 then displayed in the label in view1?

Banging my head on this one...
tmoney11 is offline   Reply With Quote
Old 04-14-2010, 06:38 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 60
imsatasia is on a distinguished road
Default

Quote:
Originally Posted by tmoney11 View Post
So in one view, I have a button the pushes another viewController with a map. The map let's the user select any location and provides an annotation with the reverseGeocode address of that location. The annotation has a button that 'pops' the view controller. Now when that button is pressed, I want it to update a label on the original view. How can this be done?

View 1 with button and label:
Code:
- (IBAction) pickLocation {
	
	MapViewController *mapcontroller = [[MapViewController alloc] initWithNibName:@"MapViewController" bundle:nil];

	mapcontroller.navigationItem.title = @"Pick Location";

	[self.navigationController pushViewController:mapcontroller animated:YES];

	[mapcontroller release];

}
View 2 with Map and annotation:
Code:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
	if ([control isKindOfClass:[UIButton class]]) {		
		
      View1Controller *view1 = [[ View1Controller alloc] init];
			view1._address = address; //  'address' is synthesized in view2
			[view1 release];
	
						
		[self.navigationController popViewControllerAnimated:YES];

	}
}


- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)newPlacemark {
	
	
	for (DDAnnotation *annotation in _annotations) {
		if (annotation.coordinate.latitude == geocoder.coordinate.latitude && annotation.coordinate.longitude == geocoder.coordinate.longitude) {
			annotation.subtitle = [[newPlacemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
			
			address = [NSString stringWithFormat:@"%@", annotation.subtitle]; // 'address' is synthesized properly
	
			
			}

	}
}

The issue is the label ends up being null. How do I ensure the 'address' value from view2 gets stored as a string in view1 then displayed in the label in view1?

Banging my head on this one...
What is "navigationItem" in
Code:
mapcontroller.navigationItem.title = @"Pick Location";
....???

if its navigationcontroller then Try following:
Code:
mapcontroller.title = @"Pick Location";
__________________
--
mySite
imsatasia is offline   Reply With Quote
Old 04-14-2010, 10:40 PM   #3 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 3
tmoney11 is on a distinguished road
Default

Thanks for the pointer. Will this help with the passing of the variables? The main problem is taking an NSString from the pushed view (view2) and displaying it back on view1 as a label.text.
tmoney11 is offline   Reply With Quote
Reply

Bookmarks

Tags
controller, label, nsstring, view change

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 318
16 members and 302 guests
chemistry, Domele, Duncan C, Fstuff, givensur, heshiming, HowEver, iAppDeveloper, iphonedevshani, jbro, JoeRCruso, kapps11, newDev, SLIC, stanny, WheyLabs
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,648
Threads: 94,112
Posts: 402,874
Top Poster: BrianSlick (7,990)
Welcome to our newest member, brandon6031
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 07:27 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0