0

I am trying to find a way to detect the button text in my app. Basically, it is a mini app-store. I have a blue install button, and when it is tapped, and turns green and says confirm. (Like the iOS App Store.) Is there a way to detect when the button displays the text "CONFIRM" so when it is tapped when it says that, the link opens to install the app? Or, another way to do this would be to detect button taps, but nothing works for me in the way I'm trying to do this. Here is my current code:

- (IBAction)buttonDownload:(id)sender {
   //in the storyboard file, the button is set to say "INSTALL"
   [sender setTitle:@"CONFIRM" forState:UIControlStateNormal];
   [sender setTitleColor:[UIColor colorWithRed:45.0f/255.0f green:152.0f/255.0f blue:0.0f/255.0f alpha:1.0] forState:UIControlStateNormal];
   [[self.appInstallOutlet layer] setBorderColor:[UIColor colorWithRed:45.0f/255.0f green:152.0f/255.0f blue:0.0f/255.0f alpha:1.0].CGColor];

//now, if the button displays "CONFIRM", open the link from a JSON file...
//Here is where the if statement should start...
    NSString *linkForApp = [self.appDetails objectForKey:@"linkForApp"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString: linkForApp]];
//end if statement

I have found a solution by using the following code:

    UIButton *resultButton = (UIButton *)sender;
if ([resultButton.currentTitle  isEqualToString: @"INSTALL"]) {
    [sender setTitle:@"CONFIRM" forState:UIControlStateNormal];
    [sender setTitleColor:[UIColor colorWithRed:45.0f/255.0f green:152.0f/255.0f blue:0.0f/255.0f alpha:1.0] forState:UIControlStateNormal];
    [[self.appInstallOutlet layer] setBorderColor:[UIColor colorWithRed:45.0f/255.0f green:152.0f/255.0f blue:0.0f/255.0f alpha:1.0].CGColor];



}
else if ([resultButton.currentTitle isEqualToString:@"CONFIRM"]) {
NSString *linkForApp = [self.restuarantDetail objectForKey:@"linkForApp"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: linkForApp]];
}
JaredH
  • 2,338
  • 1
  • 30
  • 40
anthonya1999
  • 253
  • 3
  • 13
  • 1
    you've set the title, don't you think they're be a way to access the title? Looking at UIButton.h would be a good place to start. – Patrick Goley Dec 28 '14 at 00:27
  • and then you might want to have a quick look at string comparison [NSString equalToString:(NSString *)string] ..... – Jef Dec 28 '14 at 00:29
  • @PatrickGoley the popup to install though still comes up when the button says install. I would only like it to come up after the second time when you press confirm after. – anthonya1999 Dec 28 '14 at 00:34
  • You mean something like this?http://stackoverflow.com/questions/900867/getting-title-of-uibutton-in-event-handler – JKo Dec 28 '14 at 00:36
  • @JacobKoko Okay, that's somewhat closer, but not exactly what I'm looking for. I would ONLY like that popup to appear to install if and only if it is pressed a second time, or if it can detect that it doesn't say install anymore or if it does detect that is says CONFIRM. However, if you check to see if the text is equal to "CONFIRM", it just unfortunately does nothing. – anthonya1999 Dec 28 '14 at 00:46

0 Answers0