Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3664804
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:41:16+00:00 2026-05-19T01:41:16+00:00

I’m looking to pass a user chosen value from one view to the next

  • 0

I’m looking to pass a user chosen value from one view to the next so it can be submitted to Twitter, Facebook, etc.

Would a global variable be best to implement? I don’t want the value to be stored or saved anywhere.. just to make it through the end of the navigation controller (submission to Facebook, Twitter, etc.)

Any suggestions? Thanks in advance.

Header File

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "ShareViewController.h"
#include "TwitterRushViewController.h"

@interface KindViewController : UIViewController <UIPickerViewDelegate, UIScrollViewDelegate, CLLocationManagerDelegate> {
            IBOutlet UIScrollView *scrollView;
            IBOutlet UIPageControl *pageControl;
            BOOL pageControlIsChangingPage;

            CLLocationManager *locationManager;
            NSString *finalCoordinates;
            NSString *finalChoice;
            }

@property (nonatomic, retain) UIView *scrollView;
@property (nonatomic, retain) UIPageControl *pageControl;

@property (nonatomic, retain) CLLocationManager *locationManager; 
@property (retain) NSString *finalCoordinates;
@property (nonatomic, copy) NSString *finalChoice;


-(IBAction)changePage:(id)sender;
-(IBAction)submitChoice:(id)sender;
-(void)setupPage;

@end

Implementation File

#import "KindViewController.h"
#import "JSON/JSON.h"

@implementation KindViewController
@synthesize scrollView;
@synthesize pageControl;
@synthesize locationManager;
@synthesize finalCoordinates;
@synthesize finalChoice;

#pragma mark -
#pragma mark UIView boilerplate
- (void)viewDidLoad {   
    [self setupPage];   
    [super viewDidLoad];

    // Alert the User on Location Access
    self.locationManager = [[[CLLocationManager alloc] init] autorelease];
    self.locationManager.delegate = self;
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    }

-(void)viewWillAppear:(BOOL)animated {
    [locationManager startUpdatingLocation];    
    }

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    CLLocation *location = newLocation;
    NSLog(@"Our current Latitude is %f", location.coordinate.latitude);
    NSLog(@"Our current Longitude is %f", location.coordinate.longitude);
    NSString *Coordinates = [[NSString alloc] initWithFormat: @"Longitude=%f&Latitude=%f", location.coordinate.longitude, location.coordinate.latitude ];
    NSLog(@"Test: %@", Coordinates);
    finalCoordinates = Coordinates;
    [locationManager stopUpdatingLocation]; 
    }

#pragma mark -
#pragma mark The Guts
- (void)setupPage {
    scrollView.delegate = self;
    [scrollView setCanCancelContentTouches:NO];
    scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
    scrollView.clipsToBounds = YES;
    scrollView.scrollEnabled = YES;
    scrollView.pagingEnabled = YES;

    NSUInteger nimages = 0;
    CGFloat cx = 0;
    for (; ; nimages++) {
        NSString *imageName = [NSString stringWithFormat:@"choice%d.png", (nimages + 1)];
        UIImage *image = [UIImage imageNamed:imageName];
        if (image == nil) {
            break;
        }
        UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

        CGRect rect = imageView.frame;
        rect.size.height = image.size.height;
        rect.size.width = image.size.width;
        rect.origin.x = ((scrollView.frame.size.width - image.size.width) / 2) + cx;
        rect.origin.y = ((scrollView.frame.size.height - image.size.height) / 2);

        imageView.frame = rect;

        [scrollView addSubview:imageView];
        [imageView release];

        cx += scrollView.frame.size.width;
    }
    self.pageControl.numberOfPages = nimages;
    [scrollView setContentSize:CGSizeMake(cx, [scrollView bounds].size.height)];
    }


#pragma mark -
#pragma mark UIScrollViewDelegate stuff
- (void)scrollViewDidScroll:(UIScrollView *)_scrollView {
    if (pageControlIsChangingPage) {
        return;
    }
    CGFloat pageWidth = _scrollView.frame.size.width;
    int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;
    pageControl.currentPage = page;
    }

- (void)scrollViewDidEndDecelerating:(UIScrollView *)_scrollView {
    pageControlIsChangingPage = NO;
    }


#pragma mark -
#pragma mark PageControl stuff
- (IBAction)changePage:(id)sender {
    CGRect frame = scrollView.frame;
    frame.origin.x = frame.size.width * pageControl.currentPage;
    frame.origin.y = 0;
    [scrollView scrollRectToVisible:frame animated:YES];
    pageControlIsChangingPage = YES;
    }


-(IBAction)submitChoice:(id)sender; {

    // Spinner
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(135,140,50,50)];
    [spinner startAnimating];
    [self.view addSubview:spinner];

    // Find the Date
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:@"MMM dd, yyyy HH:mm"];

    NSDate *now = [[NSDate alloc] init];
    NSString *dateString = [format stringFromDate:now];

    // Echo Everything
    NSLog(@"Type is %f.", scrollView.contentOffset.x);
    NSLog(@"Date is %@", dateString);
    NSLog(@"Coordinates are %@", finalCoordinates);

    NSString *completeURL = [[NSString alloc] initWithFormat: @"http://www.example.com/insert.php?Type=%f&Time=%@&%@", scrollView.contentOffset.x, dateString, finalCoordinates];
    NSString *escapedUrl = [completeURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSLog(@"URL is %@.", escapedUrl);

    // Post to Web Server
    NSURL *urlToSend = [[NSURL alloc] initWithString:escapedUrl];
    NSLog(@"NSURL is %@.", urlToSend);

    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:urlToSend cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30];

    NSData *urlData;
    NSURLResponse *response;
    NSError *error;
    urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];

    // Do the Button Action
    ShareViewController *shareViewController = [[ShareViewController alloc] initWithNibName:@"ShareViewController" bundle:nil];
    shareViewController.finalChoice = @"Facebook Property";
    [self.navigationController pushViewController:shareViewController animated:YES];
    [shareViewController release];

    [urlToSend release];
    [completeURL release];
    [spinner release];
    }

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"There is an error updating the location");
    }

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    }

- (void)viewDidUnload {
    [super viewDidUnload];
    [pageControl release];
    }

- (void)dealloc {
    [super dealloc];
    }

@end

ShareViewController.h

#import <UIKit/UIKit.h>
#import "MapViewController.h"
#import "SA_OAuthTwitterController.h" 
#import "FBConnect/FBConnect.h"
#import "TwitterRushViewController.h"
#import "oAuth2TestViewController.h"

@class SA_OAuthTwitterEngine;

@interface ShareViewController : UIViewController <UITextFieldDelegate, SA_OAuthTwitterControllerDelegate> {
    }

@property (nonatomic, retain) IBOutlet UIButton *shareFacebookBTN;
@property (nonatomic, retain) IBOutlet UIButton *shareTwitterBTN;
@property (nonatomic, retain) KindViewController finalChoice;


/* Submissions */
- (IBAction)shareNoThanks:(id)sender;
- (IBAction)shareFacebook:(id)sender;
- (IBAction)shareTwitter:(id)sender;

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:41:17+00:00Added an answer on May 19, 2026 at 1:41 am

    Just setting a property on the next UIViewController when you push it would probably be the easiest thing to do.

    SomeViewController *someViewController = [[SomeViewController alloc] init];
    someViewController.facebookProperty = @"Facebook Property";
    someViewController.twitterProperty = @"Twitter Property";
    [self.navigationController pushViewController:someViewController animated:YES];
    [someViewController release];
    

    Ok there are a few things wrong with ShareViewController.h. First if you have a property you also need to have an instance variable for that property. Next you are assigning a string to finalChoice but you have declared its type as KindViewController it should be NSString.

    In ShareViewController.h

    @interface ShareViewController : UIViewController <UITextFieldDelegate, SA_OAuthTwitterControllerDelegate> {
        NSString *finalChoice;
    }
    
    @property (nonatomic, retain) IBOutlet UIButton *shareFacebookBTN;
    @property (nonatomic, retain) IBOutlet UIButton *shareTwitterBTN;
    @property (nonatomic, copy) NSString *finalChoice;
    

    And make sure you @synthesize finalChoice in your implementation file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking for suggestions for debugging... If you view this site in Firefox or
I have a jquery bug and I've been looking for hours now, I can't
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm making a simple page using Google Maps API 3. My first. One marker
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.