Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-16-2011, 08:34 PM   #26 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 112
Pjgdog is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
:S

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

thanks
Pjgdog is offline   Reply With Quote
Old 02-16-2011, 08:52 PM   #27 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

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.
baja_yu is offline   Reply With Quote
Old 02-16-2011, 08:59 PM   #28 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 112
Pjgdog is on a distinguished road
Default

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");
		}
	  }	
   }
Pjgdog is offline   Reply With Quote
Old 02-16-2011, 09:06 PM   #29 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

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");
		}
	}	
}
baja_yu is offline   Reply With Quote
Old 02-16-2011, 09:15 PM   #30 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 112
Pjgdog is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
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
Pjgdog is offline   Reply With Quote
Old 02-16-2011, 09:17 PM   #31 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Did you use the code I gave you? If that didn't work then you didn't set the tag property to 2 for the other alertview.
baja_yu is offline   Reply With Quote
Old 02-16-2011, 09:20 PM   #32 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 112
Pjgdog is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
Did you use the code I gave you? If that didn't work then you didn't set the tag property to 2 for the other alertview.
Yes I used your code is this right for the tag setting?

Code:
- (IBAction)pushButton1:(id)sender {
	
	UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Your Redeeming A Freebie" message:@"Press Redeem To recieve your Service" delegate:nil cancelButtonTitle:@"No Thanks" otherButtonTitles:@"Redeem", nil];

	[alert1 show];
	[alert1 release];
    
	[alert1 setTag:2];
}

Last edited by Pjgdog; 02-16-2011 at 09:23 PM.
Pjgdog is offline   Reply With Quote
Old 02-16-2011, 09:38 PM   #33 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Yes, but move the setTag line before you call 'show'.
baja_yu is offline   Reply With Quote
Old 02-16-2011, 09:54 PM   #34 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 112
Pjgdog is on a distinguished road
Default

Thanks Ill try that
Pjgdog is offline   Reply With Quote
Old 02-16-2011, 10:21 PM   #35 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 112
Pjgdog is on a distinguished road
Default

Its not working I swiched it and the action still isnt firing

here is the code for both the actions

Code:

	- (IBAction)pushButton:(id)sender 
	{
		
		//Freebies Redeem Alert	
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your Redeeming A Freebie" message:@"Press Redeem To receive your Service" delegate:self cancelButtonTitle:@"No Thanks" otherButtonTitles:@"Redeem", nil];
	    [alert setTag:1];
		[alert show];
		[alert release];
		
		

		
	}
	


- (IBAction)pushButton1:(id)sender 
{
	UIAlertView *alert1 = [[UIAlertView alloc] initWithTitle:@"Your Redeeming A Freebie" message:@"Press Redeem To receive your Service" delegate:nil cancelButtonTitle:@"No Thanks" otherButtonTitles:@"Redeem", nil];
	[alert1 setTag:2];
	[alert1 show];
	[alert1 release];
	
		
}


#pragma mark -
#pragma mark - UIAlertViewDelegate

- (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");
		}
	}	
}
Pjgdog is offline   Reply With Quote
Old 02-16-2011, 10:33 PM   #36 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

It looks fine to me. Is the alert view not firing/showing up at all, or is the action not performed when you click a button in the second view?

If the alert shows, did you check in the console to see if NSLog is writing the messages (ok alert 2, cancel alert2) in the output?
baja_yu is offline   Reply With Quote
Old 02-16-2011, 11:19 PM   #37 (permalink)
Registered Member
 
Objective Zero's Avatar
 
Join Date: Oct 2010
Posts: 1,210
Objective Zero is on a distinguished road
Default

Lets finish this thread by giving the man his code

YouTube - Xcode Tutorial 6 - Multiple UIAlertViews in one ViewController
Objective Zero is offline   Reply With Quote
Old 02-17-2011, 02:14 AM   #38 (permalink)
- U haz disappoint -
 
Join Date: Jan 2010
Location: Belgium
Posts: 489
jNoxx is on a distinguished road
Send a message via MSN to jNoxx Send a message via Skype™ to jNoxx
Default

Thanks objective, saved to bookmarks.
jNoxx is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 371
11 members and 360 guests
cpsclicker, dre, Error404, gmarro, jeroenkeij, Kirkout, Music Man, PavelMik, teebee74, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,666
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cpsclicker
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:07 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0