multi button tag multi ple view - iphone

On click each button showing subview view contains learn and play option.While clicking , want to show the different view depends on the uibutton selection.Here my code .
-(IBAction)animals
{
CGPoint point = [tap locationInView:self.animalsbut];
pv = [PopoverView showPopoverAtPoint:point inView:animalsbut withContentView:alertvu delegate:self];
pv.tag=1;
}
-(IBAction)birds
{
CGPoint point = [tap locationInView:self.birdsbut];
pv = [PopoverView showPopoverAtPoint:point inView:birdsbut withContentView:alertvu delegate:self];
pv.tag=2;
//[self checkingme:pv.tag];
}
-(IBAction)direct
{
CGPoint point = [tap locationInView:self.direcbut];
pv = [PopoverView showPopoverAtPoint:point inView:direcbut withContentView:alertvu delegate:self];
pv.tag=4;
}
-(IBAction)fruit
{
CGPoint point = [tap locationInView:self.fruitbut];
pv = [PopoverView showPopoverAtPoint:point inView:fruitbut withContentView:alertvu delegate:self];
pv.tag=3;
}
method
-(IBAction)check:(NSInteger)sender
{
UIButton *mybutton =(UIButton*) [self.view viewWithTag:sender];
if(pv.tag==1)
{
NSLog(#"button log%d",mybutton.tag);
if(mybutton.tag==0)
{
animallearn *aview=[[animallearn alloc]initWithNibName:#"animallearn" bundle:nil];
[self.navigationController pushViewController:aview animated:YES];
[pv performSelector:#selector(dismiss) withObject:nil afterDelay:0.1f];
}
else //(mybutton.tag==1)
{
playview *pview=[[playview alloc]initWithNibName:#"playview" bundle:nil];
[self.navigationController pushViewController:pview animated:YES];
[pv performSelector:#selector(dismiss) withObject:nil afterDelay:0.1f];
}
}
else if(pv.tag==2)
{
if(mybutton.tag==0)
{
birdview *aview=[[birdview alloc]initWithNibName:#"birdview" bundle:nil];
[self.navigationController pushViewController:aview animated:YES];
[pv performSelector:#selector(dismiss) withObject:nil afterDelay:0.1f];
}
else if(mybutton.tag==1)
{
playview *pview=[[playview alloc]initWithNibName:#"playview" bundle:nil];
[self.navigationController pushViewController:pview animated:YES];
[pv performSelector:#selector(dismiss) withObject:nil afterDelay:0.1f];
}
}
else if(pv.tag==3)
{
if(mybutton.tag==0)
{
fruitview *aview=[[fruitview alloc]initWithNibName:#"fruitview" bundle:nil];
[self.navigationController pushViewController:aview animated:YES];
[pv performSelector:#selector(dismiss) withObject:nil afterDelay:0.1f];
}
else if(mybutton.tag==1)
{
playview *pview=[[playview alloc]initWithNibName:#"playview" bundle:nil];
[self.navigationController pushViewController:pview animated:YES];
[pv performSelector:#selector(dismiss) withObject:nil afterDelay:0.1f];
}
}
else if(pv.tag==4)
{
if(mybutton.tag==0)
{
directview *aview=[[directview alloc]initWithNibName:#"directview" bundle:nil];
[self.navigationController pushViewController:aview animated:YES];
[pv performSelector:#selector(dismiss) withObject:nil afterDelay:0.1f];
}
else if(mybutton.tag==1)
{
playview *pview=[[playview alloc]initWithNibName:#"playview" bundle:nil];
[self.navigationController pushViewController:pview animated:YES];
[pv performSelector:#selector(dismiss) withObject:nil afterDelay:0.1f];
}
}
else
{
return ;
}
}
Here problem is whenever i second button it showing the button tag 0 view only in all the cases?Can any one help me to sort it out

You should also set the tags of UIButtons/UIViews you want to access via tag. like secondButton.tag = 3; and the sender argument passed is not of type NSInteger it is of UIView, so change it like this! This is should solve your problem!
-(IBAction)check:(id)sender
{
UIButton *mybutton =(UIButton*) sender;
// continue whatever you were doing earlier!
}

Related

How do I get a photo from the phone gallery?

I have a huge problem as am trying to open image picker but don't know why my app crashes at this line
[self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];
I have used this this code in many application and code is working fine but in my current apps this code giving exception of preferred interface orientation.
The code which is used :
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (cameraAvailable == TRUE) {
if (buttonIndex == 0) {
imgpkrController.delegate = self;
imgpkrController.allowsEditing = YES;
imgpkrController.sourceType = UIImagePickerControllerSourceTypeCamera;
//[self presentModalViewController:(UIViewController *)imgpkrController animated:YES];
[self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];
}
else if(buttonIndex == 1){
imgpkrController.delegate = self;
imgpkrController.allowsEditing = YES;
imgpkrController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//[self presentModalViewController:(UIViewController *)imgpkrController animated:YES];
[self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];
}
}
if (buttonIndex == 0) {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
imgpkrController.delegate = self;
imgpkrController.allowsEditing = YES;
imgpkrController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//imgpkrController.modalPresentationStyle=UIModalPresentationFullScreen;
//[self presentModalViewController:imgpkrController animated:YES];
[self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];
//[self presentViewController:imgpkrController animated:YES completion:nil];
}
else{
NSLog(#"ipad photo");
imgpkrController.delegate = self;
popoverController = [[UIPopoverController alloc] initWithContentViewController:imgpkrController];
[popoverController presentPopoverFromRect:CGRectMake(260.0, 0.0, 400.0, 570.0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
else{
if (buttonIndex == 0) {
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
imgpkrController.delegate = self;
imgpkrController.allowsEditing = YES;
imgpkrController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//[self presentModalViewController:(UIViewController *)imgpkrController animated:YES];
[self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];
}else{
NSLog(#"ipad photo");
imgpkrController.delegate = self;
popoverController = [[UIPopoverController alloc] initWithContentViewController:imgpkrController];
[popoverController presentPopoverFromRect:CGRectMake(260.0, 0.0, 400.0, 570.0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
}
}
Code crashes on this line
[self presentViewController:(UIViewController *)imgpkrController animated:YES completion:nil];
with exception:
2013-07-16 15:11:02.143 HMW[1335:c07] *** Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
*** First throw call stack:
(0x2ec5012 0x2a7ce7e 0x2ec4deb 0x17a54da 0x19a444c 0x17a24f3 0x17a2777 0x2a663 0x1a952c1 0x2a90705 0x16bb920 0x16bb8b8 0x177c671 0x177cbcf 0x177bd38 0x16eb33f 0x16eb552 0x16c93aa 0x16bacf8 0x38a7df9 0x38a7ad0 0x2e3abf5 0x2e3a962 0x2e6bbb6 0x2e6af44 0x2e6ae1b 0x38a67e3 0x38a6668 0x16b865c 0x2802 0x2735)
libc++abi.dylib: terminate called throwing an exception
Not sure what's causing your error message as it seems to be related to the device orientation but I managed to get this working with the following code:
- (IBAction)attachPhotosClicked:(id)sender
{
if (![UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear])
{
_imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[_popoverController presentPopoverFromRect:self.attachButton.frame inView:self.view
permittedArrowDirections:(UIPopoverArrowDirectionLeft)
animated:YES];
return;
}
else
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Choose a source"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:#"Camera", #"Photo Library", nil];
[actionSheet showFromRect:self.attachButton.frame inView:self.view animated:YES];
}
}
- (IBAction)selectPhoto:(UIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
You will find this issue in iOS 6.0. have a look at the following link,
UIPopoverController orientation crash in iOS 6
It should be fixed in later versions.
I think your problem is due to an iOs version problem. The interfaceOrientation protocol is changed in iOs 6.
I think this link could help you.
preferredInterfaceOrientationForPresentation must return a supported interface orientation?

UISwipeGestureRecognizer making app crash changing screens?

I have a simple 3 page app, I can go from page 1 to page 2 swiping left.
However, when I am on page 2, I need to add the ability to go to either page 1 swiping right, or page 3 swiping left, but it just keeps crashing.
I suspect it may be a memory release issue, but I wonder if you could be so kind as to check the code below for any glaring errors?
Many thanks,
- (void)viewDidLoad {
UISwipeGestureRecognizer *swipeLeftRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
[swipeLeftRight setDirection:(UISwipeGestureRecognizerDirectionRight | UISwipeGestureRecognizerDirectionLeft )];
[self.view addGestureRecognizer:swipeLeftRight];
[UISwipeGestureRecognizer release];
}
- (IBAction)swipeLeftDetected:(UISwipeGestureRecognizer *)sender {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
Page3ViewController *UIViewController =
[[Page3ViewController alloc] initWithNibName:#"Page3ViewController~ipad" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
[Page2ViewController release];
}else{
Page3ViewController *UIViewController =
[[Page3ViewController alloc] initWithNibName:#"Page3ViewController" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
[Page2ViewController release];
}
}
- (IBAction)swipeRightDetected:(UISwipeGestureRecognizer *)sender {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
ViewController *UIViewController =
[[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
[Page2ViewController release];
}else{
ViewController *UIViewController =
[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
ViewController *VC = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self presentModalViewController:VC animated:YES];
[Page2ViewController release];
}
}
EDIT:
You need to implement a method called handleGesture: since that's the action you're passing in to the gesture recognizer.
Fixed, I found an older post by a person called rptwsthi, I used some of that to fix it;
Changed the viewDidLoad {
UISwipeGestureRecognizer *rightRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(rightSwipeHandle:)];
rightRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
[rightRecognizer setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:rightRecognizer];
[rightRecognizer release];
//........towards left Gesture recogniser for swiping.....//
UISwipeGestureRecognizer *leftRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(leftSwipeHandle:)];
leftRecognizer.direction = UISwipeGestureRecognizerDirectionLeft;
[leftRecognizer setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:leftRecognizer];
[leftRecognizer release];
And using this to switch the pages;
- (void)rightSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
//Do moving
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
ViewController *UIViewController =
[[ViewController alloc] initWithNibName:#"ViewController_iPad" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
[Page2ViewController release];
}else{
ViewController *UIViewController =
[[ViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
ViewController *VC = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self presentModalViewController:VC animated:YES];
[Page2ViewController release];
}
}
- (void)leftSwipeHandle:(UISwipeGestureRecognizer*)gestureRecognizer
{
// do moving
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
Page3ViewController *UIViewController =
[[Page3ViewController alloc] initWithNibName:#"Page3ViewController~ipad" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
}else{
Page3ViewController *UIViewController =
[[Page3ViewController alloc] initWithNibName:#"Page3ViewController" bundle:nil];
[self presentModalViewController:UIViewController animated:YES];
}
}
Not sure how neat it is in a true coders view, but it works, sometimes you just gotta go with what works right! :)

Black screen appears, randomly after taking an image and tapping 'USE' in the UIImagePickerController

I have an app that's almost done and now while it was under QA, the QA engineer came across a random issue in which a black screen appears after tapping on USE in UIImagePickerController view. Further in didFinishPickingMediaWithInfo the image is being saved for future refrencing and is being shown in an UIImageView, I am also using camera overlay for adding a button to the UIImagePickerView and the max memory usage of the app doen't goes beyond 13 MB. The issue is not arising when switching to Camera roll mode from capture mode. Also in the same view iADs are being presented. Underneath is the code, to which the issue may concern, also images are being attached to get an idea of the issue. Any help would be greatly appreciated.
Thanks in advance.
(void) launchCamera
{
// Set up the camera\
CustomCameraView *cameraController = [[CustomCameraView alloc] init];
cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraController.delegate = self;
cameraController.showsCameraControls = YES;
cameraController.navigationBarHidden = YES;
cameraController.toolbarHidden = YES;
// overlay on top of camera lens view
UIButton *cameraRoll = [[UIButton alloc] initWithFrame:CGRectMake(15, 380, 40, 40)];
[cameraRoll setAlpha:0.0f];
[cameraRoll setBackgroundImage:[UIImage imageNamed:#"CamerRoll_New"] forState:UIControlStateNormal];
[cameraRoll addTarget:self action:#selector(switchToCameraRoll) forControlEvents:UIControlEventTouchUpInside];
cameraController.cameraOverlayView = cameraRoll;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:1.5f];
cameraRoll.alpha = 1.0f;
[UIView commitAnimations];
[self presentModalViewController:cameraController animated:YES];
}
-(void)switchToCameraRoll
{
DLog(#"Camera Roll");
[self dismissViewControllerAnimated:NO completion:^(void){ [self photoSourcePhotoAlbum];}];
}
-(void) photoSourcePhotoAlbum
{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self.view addSubview:progressView];
timer = [NSTimer scheduledTimerWithTimeInterval:.017 target:self selector:#selector(progressChange) userInfo:nil repeats:YES];
[picker dismissModalViewControllerAnimated:YES];
[self performSelectorInBackground:#selector(saveImage:) withObject:info];
[self performSelector:#selector(navigateToEditView) withObject:nil afterDelay:2.1];
}
-(void)navigateToEditView
{
[self performSegueWithIdentifier:#"presentRDetailModalViewController" sender:self];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
if (picker.sourceType == UIImagePickerControllerSourceTypeSavedPhotosAlbum)
{
[picker dismissViewControllerAnimated:NO completion:^(void){ [self photoSourceCamera];}];
}
else
{
[picker dismissModalViewControllerAnimated:YES];
}
}
-(void)saveImage:(NSDictionary *)info
{
NSString *imageName = [[[DataStaging dataStaging] getGUID] stringByAppendingString:#".jpg"];
rImageName = imageName;
UIImage *rImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
//Compress image
[[FileOperations fileOperations] PersistData:UIImageJPEGRepresentation(rImage, 0.4) name:imageName];
DLog(#"%#",[[FileOperations fileOperations] fetchPath:imageName]);
//Actual image taken
[[self rImageView] setImage:[info objectForKey:#"UIImagePickerControllerOriginalImage"]];
if ([rImageName length] == 0)
{
[[self rDetails] setHidden:YES];
[[self trashRImage] setHidden:YES];
}
else
{
[[self rDetails] setHidden:NO];
[[self trashRImage] setHidden:NO];
}
[progressView removeFromSuperview];
}
}
Make sure you don't call presentModalViewController:animated: twice before dismissModalViewControllerAnimated:
It helped in my case.
- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
if (_imagePickerController!=nil || _imagePopoverController!=nil) {
return;
}
_imagePickerController = [[[UIImagePickerController alloc] init] autorelease];
_imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
_imagePickerController.sourceType = sourceType;
_imagePickerController.delegate = self;
switch (sourceType) {
case UIImagePickerControllerSourceTypeCamera:
_imagePickerController.showsCameraControls = YES;
[self presentViewController:_imagePickerController animated:YES completion:nil];
break;
default:
_imagePopoverController = [[UIPopoverController alloc] initWithContentViewController:_imagePickerController];
_imagePopoverController.delegate = self;
CGRect rect = [[UIScreen mainScreen] bounds];
rect.origin.y = rect.size.height - 70.0;
rect.size.height -= rect.origin.y;
[_imagePopoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
break;
}
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
{
[_imagePopoverController dismissPopoverAnimated:YES];
_imagePopoverController = nil;
[_imagePickerController dismissViewControllerAnimated:YES completion:nil];
_imagePickerController = nil;
}
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
UIImageWriteToSavedPhotosAlbum([info objectForKey:UIImagePickerControllerOriginalImage],nil,nil,nil);
_currentImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[_imagePopoverController dismissPopoverAnimated:YES];
_imagePopoverController = nil;
[_imagePickerController dismissViewControllerAnimated:YES completion:nil];
_imagePickerController = nil;
}

How to call gesture swipe method from another method in Objective-c

I have this gesture swipe method that I want to call from another method using
[self performSelector:#selector(handleSwipeGesture:)
withObject:nil afterDelay:10];
I can't figure out the syntax to put in the #selector()
any help is appreciated. here's my code:
- (IBAction)handleSwipeGesture:(UISwipeGestureRecognizer *)sender {
if(sender.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(#"swipe left");
TutorialMenuViewController *tutorialMenuViewController = [[TutorialMenuViewController alloc]
initWithNibName:#"TutorialMenuViewController" bundle:nil];
[self.navigationController pushViewController:tutorialMenuViewController animated:YES];
[tutorialMenuViewController release];
}
}
If you want to present TutorialMenuViewController either on a gesture or time delay you would be better off just abstracting its presentation out into a different method
- (IBAction)handleSwipeGesture:(UISwipeGestureRecognizer *)sender {
if(sender.direction == UISwipeGestureRecognizerDirectionLeft) {
[self presentTutorial];
}
}
- (void)presentTutorial;
{
TutorialMenuViewController *tutorialMenuViewController = [[TutorialMenuViewController alloc]
initWithNibName:#"TutorialMenuViewController" bundle:nil];
[self.navigationController pushViewController:tutorialMenuViewController animated:YES];
[tutorialMenuViewController release];
}
Now you can simply call
[self performSelector:#selector(presentTutorial) withObject:nil afterDelay:10];
- (IBAction)handleSwipeGesture:(UISwipeGestureRecognizer *)sender {
if(sender.direction == UISwipeGestureRecognizerDirectionLeft) {
NSLog(#"swipe left");
//TutorialMenuViewController *tutorialMenuViewController = [[TutorialMenuViewController alloc]
// initWithNibName:#"TutorialMenuViewController" bundle:nil];
//[self.navigationController pushViewController:tutorialMenuViewController animated:YES];
//[tutorialMenuViewController release];
}
}
Called it like this:
UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:nil action:nil];
[leftSwipe setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[self performSelector:#selector(handleSwipeGesture:) withObject:leftSwipe afterDelay:1];
[leftSwipe release];

Pause the Views from Updating

Want to pause the multiple views from updating when Pause button is pressed
In h file
#property BOOL appIsPaused;
In m file
#synthesize appIsPaused;
-(void)playpauseAction:(id)sender
{
if
([audioPlayer isPlaying]){
[sender setImage:[UIImage imageNamed:#"play.png"] forState:UIControlStateSelected];
[audioPlayer pause];
appIsPaused = YES;
} else {
[sender setImage:[UIImage imageNamed:#"pause.png"] forState:UIControlStateNormal];
[audioPlayer play];
appIsPaused = NO;
[self performSelector:#selector(displayviewsAction:) withObject:nil afterDelay:11.0];
}
}
- (void)displayviewsAction:(id)sender
{
FirstViewController *viewController = [[FirstViewController alloc] init];
viewController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:viewController.view];
[self.view addSubview:toolbar];
[self performSelector:#selector(secondViewController) withObject:nil afterDelay:23];
[viewController release];
}
-(void)secondViewController {
SecondViewController *secondController = [[SecondViewController alloc] init];
secondController.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:secondController.view];
[self.view addSubview:toolbar];
[self performSelector:#selector(ThirdviewController) withObject:nil afterDelay:27];
[secondController release];
}
and it goes on like this for multiple views.
Any ideas how to pause views from updating whenever pause button is pressed.
Instead of using performSelector after delay, you should consider using a NSTimer.
Like this:
Declare a NSTimer *timer ivar.
Declare a NSUInteger viewControl;
Set viewControl to 0;
On the play part of the method add this line:
timer = [NSTimer scheduledTimerWithTimeInterval:11 target:self selector:#selector(tick) userInfo:nil repeats:YES];
-(void)tick
{
switch(viewControl)
{
case 0:
[self performSelector:#selector(firstViewController) withObject:nil];
break;
case 1:
[self performSelector:#selector(secondViewController) withObject:nil];
break;
case 2:
[self performSelector:#selector(thirdViewController) withObject:nil];
break;
.
.
.
default:
break;
}
viewControl++;
if(viewControl > MAX_VIEWS)
{
viewControl = 0;
}
}
And add this line on pause action:
[timer invalidate]
It is also cleaner and let you have more control over your code.
Hope it helps.