Help with error in program

General discussion about iOS development - a great place to ask questions about iOS or help out others. For discussion of the official tutorials, see the Official Tutorials forum.

Help with error in program

Postby hawkman4188 » Thu Apr 26, 2012 7:35 pm

Hi,

I just started learning to code for iOS. I am following along with a tutorial in a book I bought and I have one error that I can not figure out.

The error is: No visible @interface for 'UIAlertView' declares the selector 'initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitle:'

Here is my code for the page the error is on:
Code: Select all
#import "BINViewController.h"



@implementation BINViewController
@synthesize nameField;
@synthesize numberField;
@synthesize sliderLabel;
@synthesize leftSwitch;
@synthesize rightSwitch;
@synthesize doSomethingButton;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
   // Do any additional setup after loading the view, typically from a nib.
   
    UIImage *buttonImageNormal = [UIImage imageNamed:@"whiteButton.png"];
    UIImage *stretchableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    [doSomethingButton setBackgroundImage:stretchableButtonImageNormal forState:UIControlStateNormal];
    UIImage *buttonImagePressed = [UIImage imageNamed:@"blueButton.png"];
    UIImage *stretchableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];
    [doSomethingButton setBackgroundImage:stretchableButtonImagePressed forState:UIControlStateHighlighted];
}

- (void)viewDidUnload
{
    [self setNameField:nil];
    [self setNumberField:nil];
    [self setSliderLabel:nil];
    [self setLeftSwitch:nil];
    [self setRightSwitch:nil];
    [self setDoSomethingButton:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (IBAction)textFieldDoneEditing:(id)sender {
    [sender resignFirstResponder];
}

- (IBAction)sliderChanged:(id)sender {
   
    UISlider *slider = (UISlider*)sender;
    int progressAsInt = (int)roundf(slider.value);
    sliderLabel.text = [NSString stringWithFormat:@"%d", progressAsInt];
}

- (IBAction)switchChanged:(id)sender {
   
    UISwitch *whichSwitch = (UISwitch*)sender;
    BOOL setting = whichSwitch.isOn;
    [leftSwitch setOn:setting animated:YES];
    [rightSwitch setOn:setting animated:YES];
}

- (IBAction)toggleControls:(id)sender {
   
    // 0 == switches index
    if ([sender selectedSegmentIndex] == 0) {
        leftSwitch.hidden = NO;
        rightSwitch.hidden = NO;
        doSomethingButton.hidden = YES;
    }
    else {
        leftSwitch.hidden = YES;
        rightSwitch.hidden = YES;
        doSomethingButton.hidden = NO;
    }
}

- (IBAction)buttonPressed:(id)sender {
   
    UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                  initWithTitle:@"Are You Sure?" delegate:self cancelButtonTitle:@"No Way!" destructiveButtonTitle:@"Yes I'm Sure!" otherButtonTitles:nil];
    [actionSheet showInView:self.view];
}

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex != [actionSheet cancelButtonIndex])
    {
       
        NSString *msg = nil;
       
        if (nameField.text.length > 0)
           
            msg = [[NSString alloc] initWithFormat:@"You can breathe easy, %@, everything went OK.", nameField.text];
        else
            msg = @"You can breathe easy, everything went ok.";

//This is where the error is
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle:@"Something was done"
                              message:msg
                              delegate:self
                              cancelButtonTitle:@"Phew!"
                              otherButtonTitle:nil];
        [alert show];
       
    }
}


- (IBAction)backgroundTap:(id)sender {
   
    [nameField resignFirstResponder];
    [numberField resignFirstResponder];
}


@end


If anyone could help point me in the right direction, it would be much appreciated. Thanks!
hawkman4188
n00b
 
Posts: 2
Joined: Thu Apr 26, 2012 7:29 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Help with error in program

Postby rcasey » Thu Apr 26, 2012 8:27 pm

hawkman4188 wrote:
Code: Select all
//This is where the error is
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle:@"Something was done"
                              message:msg
                              delegate:self
                              cancelButtonTitle:@"Phew!"
                              otherButtonTitle:nil];


Just a typo on the parameter name. otherButtonTitle should be otherButtonTitles

Have fun!
rcasey
Team Member
Forum Subject Matter Expert
 
Posts: 1246
Joined: Fri Jul 01, 2011 6:50 pm
Has thanked: 2 times
Been thanked: 268 times

Re: Help with error in program

Postby hawkman4188 » Thu Apr 26, 2012 8:30 pm

:D Great! Thanks for your help! I had just been looking at the screen for so long trying to figure it out.
hawkman4188
n00b
 
Posts: 2
Joined: Thu Apr 26, 2012 7:29 pm
Has thanked: 0 time
Been thanked: 0 time


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 9 guests