Friday, February 6, 2009

UIAlertViewDelegate & Quotes

Was able to bang out UIAlertViewDelegate aspect. Now the user is gets an alert when they try to reset the counts. Basically asking for a confirmation/cancellation. This was really easy. You just extend your ViewController, define your alertView method and you're done.

This calls and opens the Alert popup window!

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your title here"
message:@"Your message here!"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Yes, Reset!", nil];
[alert show];
[alert release];


This is the method where you define what happens when the user presses "Ok"

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 1){ // 1 corresponds to the "ok" button!
// stuff here!
}
}



After that I added in a rudimentary quote handler. At first I kept getting a null object when I was reading the text file into the array. Then I realized my calls were looking in the Documents folder rather than in the App's bundle which is where the source file would be located. Fixed that. Now it works. I currently just have it cycling through the quotes once per poke. and using the modulus operator to cycle back to the beginning. I will make this more complicated later, so it doesn't just spit out the quote every time. I still haven't decided betwee random or regular intervals.

No comments:

Post a Comment