You can not name delegate methods as you wish. alertView:clickedButtonAtIndex: is the name and it has to be like that. Only one method can exist in the delegate and it will be called for every alertview. To differentiate between alertviews, set their Tag property to different values (integers), then in the clickedButtonAtIndex method check the tag value to know which alertview invoked the method, then check buttonIndex to know what action to do.
You can not name delegate methods as you wish. alertView:clickedButtonAtIndex: is the name and it has to be like that. Only one method can exist in the delegate and it will be called for every alertview. To differentiate between alertviews, set their Tag property to different values (integers), then in the clickedButtonAtIndex method check the tag value to know which alertview invoked the method, then check buttonIndex to know what action to do.
Although I know what the problem is from the previous code, saying "it didn't work" is worse than saying nothing at all. You have to explain your problem, did you get an error, which (exact message), on which line of code etc. If not, what did the code do, what did you expect it to do and so on.
In your case you are trying to set the tag property of the alert object that you did not yet declare or initialize. You need to set it after.
Although I know what the problem is from the previous code, saying "it didn't work" is worse than saying nothing at all. You have to explain your problem, did you get an error, which (exact message), on which line of code etc. If not, what did the code do, what did you expect it to do and so on.
In your case you are trying to set the tag property of the alert object that you did not yet declare or initialize. You need to set it after.
ok the error message is this
'alert' Undeclared
on this code
[alert setTag:1];
how can this be fixed
You should really get a book on basics of programming, intro to Objective C or something like that. Just copy/pasting code will only get you frustrated and you'll pick up bad habits and learn wrong.
You declared it one line below: UIAlertView *alert = ...
As for your code, you are now setting the tag after you release alert, which might work but isn't good practice to do, set the tag after you declare it, and before you show the alert.
As I said, if you have more than one alert view, be sure to set their tags to different numbers before showing them, so you can later identify them by those numbers when a button is clicked. The same way you check the buttonIndex to see which button was pressed, you need to check the tag to see which alertview is in question.
As I said, if you have more than one alert view, be sure to set their tags to different numbers before showing them, so you can later identify them by those numbers when a button is clicked. The same way you check the buttonIndex to see which button was pressed, you need to check the tag to see which alertview is in question.
Didnt I Do that by saying
([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];
I've told you this three times already, there is no condition after else, and certainly no semi-colon. I'm surprised that the code even gets passed compiler.
It's either
Code:
} else {
//stuff
}
or
} else if (condition) {
//stuff
}
I'm not answering any more until you start putting [code] tags around the code in your posts.
I've told you this three times already, there is no condition after else, and certainly no semi-colon. I'm surprised that the code even gets passed compiler.
It's either
Code:
} else {
//stuff
}
or
} else if (condition) {
//stuff
}
I'm not answering any more until you start putting [code] tags around the code in your posts.
Ok I got the first one to work but now Im facing another Problom
When I use My Second alert view the action does not execute
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;
}
else (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];