-3

I am new to iOS app development. I want to create a Calculator App in iOS that has split view. The left side is the "History" Feature in Scroll View and the right side is the calculator itself. Now, regarding the History feature of this app, I am thinking that my program needs to recognize what has been pressed and display it on the Scroll View when the Equal (=) button is pressed. Do you have any idea how will this go on Objective-C? I am using XCode 4.5 and iPhone Simulator 6.0.

Thanks in Advance!

1
  • 2
    try to google more and read about ios development in the ios developer website. if you are confused about certain code/usage then you can ask it in SO. we are not here to create your code but maybe we can provide a better solution for what you need
    – Joshua
    Jun 7, 2013 at 7:31

2 Answers 2

0

If you want to communicate/send data between views or view controllers there are several options.

If you try to communicate/send data between views and you have reference to both views you can simply call the methods from your views for example

LeftView.h

@interface LeftView : UIView {
   //instance variables here
}
//properties here
//other methods here
-(NSInteger)giveMeTheValuePlease;
@end

LeftView.m

@implementation LeftView 
//synthesise properties here
//other methods implementation here

-(NSInteger)giveMeTheValuePlease {
   return aValueThatIsInteger; //you can do other computation here
}

RightView.h

  @interface RightView : UIView {
       //instance variables here
    }
    //properties here
    //other methods here
    -(NSInteger) hereIsTheValue:(NSInteger)aValue;
    @end

RightView.m

 @implementation LeftView 
    //synthesise properties here
    //other methods implementation here

    -(void)hereIsTheValue:(NSInteger)aValue {
         //do whatever you want with the value
    }

AViewController.m

@implementation AViewController.m
//these properties must be declared in AViewController.h
@synthesise leftView;
@synthesise rightView;

-(void)someMethod {
   NSInteger aValue = [leftView giveMeTheValuePlease];
   [rightView hereIsTheValue:rightView];
}

You can use the delegate pattern (very very common in iOS), a short and basic example of delegate you can find in one of my SO answer at this link

You can also use blocks to communicate/send data between views/view controllers but this topic I think you will use a little bit later and for you will have to google a little bit in order to get a basic idea of iOS blocks.

2
  • Okay. Thanks for this. But let's go somewhere deeper than what I have said in my question. My real goal is to get the input data from the buttons on calculator on the RightView, and display it on a TableView(w/c is initially empty) on the LeftView. e.g I pressed 1+1-1*0=, when I press the equals button, all this characters will be displayed automatically on a cell in the Table View (including the answer). Do you have an advise or do you know any available tutorial for this kind of passing data? Thanks again. More Power. :)
    – caribbean
    Jun 11, 2013 at 5:57
  • You can use delegates to communicate between views, but since you have a tableView you will need a data source for it, so when the equals button is tapped, you should call a delegate method from the view which contains your table view (or view controller) that will add the string from left view to the table view data source and it will call [tableView reloadData] after that.
    – danypata
    Jun 11, 2013 at 10:06
0

Here is the solution for this requirement.

In my case.. I have 2 buttons in viewcontroller. When I click on those buttons I had to display popover. For this I had to detect which button is clicked in PopoverController(AnotherViewController).

First I have taken @property BOOL isClicked; in AppDelegate.h

And in AppDelegate.m @synthesize isClicked; (synthesized it) and in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    isClicked = FALSE;
}

Now in ViewController.m where action is implemented for buttons changed like this,

- (IBAction)citiesButtonClicked:(id)sender
{
    AppDelegate *delegate = [UIApplication sharedApplication].delegate;
    delegate.isClicked = FALSE;
}

- (IBAction)categoryButtonClicked:(id)sender
{
    AppDelegate *delegate = [UIApplication sharedApplication].delegate;
    delegate.isClicked = TRUE;
}

PopoverViewController (AnotherViewController) in -(void)viewDidLoad method

-(void)viewDidLoad {
{
    AppDelegate *delegate = [UIApplication sharedApplication].delegate;
    if (delegate.isClicked)
    {
        delegate.isClicked = FALSE;
        NSLog(@"popover clicked");
    }
    else
    {
        delegate.isClicked = TRUE;
        isClicked = YES;
    }
}

I hope it helps. Let me know if you need any help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.