You didn't close the code tags properly. Read post #17 again.
You didn't fix the else blocks. Read post #23 again.
Also, imageWithContentsOfFile returns an autoreleased object, you should't be releasing them.
Im sorry For frusturating you but this is my first time devoloping this complex of an application I am 14 and just began coding I dont fully understand everything that your saying could you maybe tell me What to do in more simpiler terms
It's obvious that you are a complete beginner, and you don't need to apologize for that. Even the best of us had to start from zero. But it's how you approach it that will determine how fast and well you learn. You wouldn't jump into the deep end of a pool without taking a few lessons first.
Objective C isn't the best choice really for someone new to programming. A run through procedural programming and simple data types and structures will do you a world of good before starting with object oriented programming. That's one of the reasons that schools teach languages like Pascal to introduce students to programming.
You should grab an intro book like Objective C for dummies, or Objective C for Absolute Beginners (I'll send you a few links on PM), and read them. There really is a lot to cover and it would take a lot to do it over a forum. A book will take you step by step, with sample code and all. I know it's not always fun to read, but it's the best way to learn in the shortest amount of time.
There's also some video lessons and tutorials in iTunes-U, from Stanford I believe that some members here suggest, but I haven't seen them so I don't know what the content is, but viewing videos will certainly cover less ground and take more time.
Thanks for the advice and the help I looking torwards purchasing a few books next week but I really need this app done It is for my dads company and Im on the last few steps of the code
But what I really need help with is getting the second Alert
view To execute and action can you show me How my code should be formatted in comparison to how it is formatted
thanks
note I have both alert Views in this code
Code:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if ([alertView tag] == 1)
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 1);
{
//NSLog(@"ok");
UIImage *img = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image1bw" ofType:@"png"]];
[image1bw setImage:img];
[img release];
btn1.hidden = YES;
}
if (buttonIndex == 0)
{
//NSLog(@"cancel");
}
}
if ([alertView tag] == 2)
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 1);
{
//NSLog(@"ok");
UIImage *img1 = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image2bw" ofType:@"png"]];
[image2bw setImage:img1];
[img1 release];
btn2.hidden = YES;
}
if (buttonIndex == 0)
{
//NSLog(@"cancel");
}
}
}
Your code there is basically ok except there's no semi-colon after if so it should be: if (buttonIndex == 1) instead of: if (buttonIndex == 1);
And you should be releasing img and img1.
Code:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([alertView tag] == 1) { //it's the first alertview
if (buttonIndex == 1) {
NSLog(@"ok alert 1");
[image1bw setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image1bw" ofType:@"png"]]];
[btn1 setHidden:YES];
} else { //if index is not 1 then it must be 0 since we only have two buttons
NSLog(@"cancel alert 1");
}
}
if ([alertView tag] == 2) { //it's second alert
if (buttonIndex == 1) {
NSLog(@"ok alert 2");
[image2bw setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image2bw" ofType:@"png"]]];
[btn2 setHidden:YES];
} else {
NSLog(@"cancel alert 2");
}
}
}
Your code there is basically ok except there's no semi-colon after if so it should be: if (buttonIndex == 1) instead of: if (buttonIndex == 1);
And you should be releasing img and img1.
Code:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if ([alertView tag] == 1) { //it's the first alertview
if (buttonIndex == 1) {
NSLog(@"ok alert 1");
[image1bw setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image1bw" ofType:@"png"]]];
[btn1 setHidden:YES];
} else { //if index is not 1 then it must be 0 since we only have two buttons
NSLog(@"cancel alert 1");
}
}
if ([alertView tag] == 2) { //it's second alert
if (buttonIndex == 1) {
NSLog(@"ok alert 2");
[image2bw setImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image2bw" ofType:@"png"]]];
[btn2 setHidden:YES];
} else {
NSLog(@"cancel alert 2");
}
}
}
I just fixed all of that but now the second action will not execute