Can't receive touch events in custom UIView with XIB - objective-c

I have a view controller that contains a scroll view. Inside of the scroll view, I have a custom header view with its own custom NIB. The issue I am having is that touch events on a button inside the custom view are not being fired. From reading other answers, I tried setting my custom view's clipsToBounds property to YES, and doing so results in no visible content for the header view. This is probably part of the problem, but I don't know how to fix it. My code below:
In the view controller:
#interface MyViewController ()
#property (weak, nonatomic) DetailHeaderView *headerView; // The custom view placed inside contentView
#property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
#property (weak, nonatomic) IBOutlet UIView *contentView; // content view for scrollView
#end
#implementation MyViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Load the Header View
NSArray *views = [[NSBundle mainBundle] loadNibNamed:#"DetailHeaderView" owner:nil options:nil];
self.headerView = [views firstObject];
self.headerView.psychic = self.psychic;
// Add the header view to the scroll view
[self.contentView addSubview:self.headerView];
[self setConstraints];
}
-(void)setConstraints {
[self.view removeConstraints:self.view.constraints];
[self.scrollView removeConstraints:self.scrollView.constraints];
[self.contentView removeConstraints:self.contentView.constraints];
[self.headerView removeConstraints:self.headerView.constraints];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.view);
make.right.equalTo(self.view);
make.top.equalTo(self.view);
make.bottom.equalTo(self.view);
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
make.width.equalTo(self.scrollView);
}];
[self.headerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView);
make.left.equalTo(self.contentView);
make.width.equalTo(self.contentView);
make.height.equalTo(#120);
}];
}
And in my custom view file:
#interface DetailHeaderView()
#property (weak, nonatomic) IBOutlet UIPhotoView *photoView;
#property (weak, nonatomic) IBOutlet UILabel *levelLabel;
#property (weak, nonatomic) IBOutlet UILabel *experienceLabel;
#property (weak, nonatomic) IBOutlet UIView *horizontalRuleView;
#property (weak, nonatomic) IBOutlet StarRatingView *ratingView;
#property BOOL constraintsAlreadySet;
#end
#implementation DetailHeaderView
-(void)updateConstraints {
[super updateConstraints];
// self.clipsToBounds = YES; <- When I uncomment this, I see nothing.
[self removeConstraints:self.constraints];
[self.photoView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self).with.offset(20);
make.left.equalTo(self).with.offset(8);
make.width.equalTo(#120);
make.height.equalTo(#100);
}];
[self.levelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.photoView).with.offset(8);
make.left.equalTo(self.photoView.mas_right).with.offset(8);
}];
// self.priceButton below is the button that is not clickable.
// It is not set as a property in this .m file because it is declared as a
// public property in the .h so that the parent view can respond to events.
[self.priceButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.levelLabel);
make.right.equalTo(self).with.offset(-8);
}];
[self.horizontalRuleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.levelLabel);
make.top.equalTo(self.levelLabel.mas_bottom).with.offset(8);
make.right.equalTo(self.priceButton);
make.height.equalTo(#1);
}];
[self.experienceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.horizontalRuleView.mas_bottom).with.offset(8);
make.left.equalTo(self.horizontalRuleView);
}];
[self.ratingView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.experienceLabel.mas_bottom).with.offset(8);
make.left.equalTo(self.experienceLabel);
}];
}
Again, without setting clipsToBounds in "DetailHeaderView", I see all the content, but the self.priceButton property does not have touch events sent.
Any help would be greatly appreciated!

Something in your view hierarchy is preventing touches or else swallowing them. My guess is you need to set userInteractionEnabled=YES on the contentView and/or the headerView.

Related

IBAction Method not being called when button is pushed. But View controller is being pushed

I am attempting to pass information from one viewController to another using a push segue with an IBAction button named *line. However from what I can tell this method is not being called and the NSLog(#"%#", see); I inserted to test the method is not displaying any message. Here is some code for the first viewController.
DetailController.m
#import "DetailController.h"
#import "City.h"
#import "ViewController.h"
#import "VideoController.h"
#import "Helper.h"
#interface DetailController ()
#property (nonatomic, strong) IBOutlet VideoController *videoViewController;
#end
#implementation DetailController
#synthesize city, ClubName, Price, Vip, Promo, remain,p,deal,money,camera,tweet,post;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
self.videoViewController = [[VideoController alloc] init];
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(320,1400)];
[super viewDidLoad];
UIImage *highlightedButtonImage = [UIImage imageNamed:#"twitter.png"];
UIImage *highlightedButtonImage2 = [UIImage imageNamed:#"twitter2.png"];
[Helper customizeBarButton:self.tweet image:highlightedButtonImage highlightedImage:highlightedButtonImage2];
UIImage *faceButtonImage = [UIImage imageNamed:#"facebook.png"];
UIImage *faceButtonImage2 = [UIImage imageNamed:#"facebook2.png"];
[Helper customizeBarButton:self.post image:faceButtonImage highlightedImage:faceButtonImage2];
UIImage *taxiButtonImage = [UIImage imageNamed:#"taxi.png"];
UIImage *taxiButtonImage2 = [UIImage imageNamed:#"taxi2.png"];
[Helper customizeBarButton:self.taxi image:taxiButtonImage highlightedImage:taxiButtonImage2];
// Do any additional setup after loading the view.
UIFont *labelFont=[UIFont fontWithName:#"King Kikapu" size:15.0];
UIFont *myFont=[UIFont fontWithName:#"Deutsch Gothic" size:20.0];
UIFont *myFont2=[UIFont fontWithName:#"Deutsch Gothic" size:35.0];
UIFont *titleFont=[UIFont fontWithName:#"Pornstar" size:50.0];
NSString * name= self.city.clubName;
NSString * line= self.city.clubLine;
NSString * description= self.city.promo;
NSString * price= self.city.price;
NSString *ipCam= self.city.camera;
remain.font=labelFont;
remain.text=#"VIP Remaining :";
p.font=labelFont;
p.text=#"Price :";
money.font=myFont;
deal.font=labelFont;
deal.text=#"Promotions :";
ClubName.font=titleFont;
ClubName.text=name;
Vip.font=myFont2;
Vip.text=line;
Price.font=myFont2;
Price.text=price;
Promo.font=myFont;
Promo.text=description;
}
- (IBAction)PostFacebook:(id)sender {
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
SLComposeViewController * facebook= [[SLComposeViewController alloc]init];
facebook= [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[facebook setInitialText:[NSString stringWithFormat:#"I'm heading to"]];
[self presentViewController:facebook animated:YES completion:nil];
[facebook setCompletionHandler:^(SLComposeViewControllerResult result){
NSString * output;
switch (result) {
case SLComposeViewControllerResultCancelled:
output=#"Action Cancelled";
break;
case SLComposeViewControllerResultDone:
output=#"Post Succesful";
default:
break;
}
UIAlertView *alert= [[UIAlertView alloc]initWithTitle:#"Facebook" message:output delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil, nil];
[alert show];
}];
}}
- (IBAction)PostTwitter:(id)sender {
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter])
{
SLComposeViewController *tweetSheet= [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:#"I'm heading to"];
[self presentViewController: tweetSheet animated:YES completion:nil];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)line:(id)sender {
NSString *see=self.city.camera;
NSLog(#"%#", see);
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard"
bundle:nil];
self.videoViewController = [storyboard instantiateViewControllerWithIdentifier:#"Page3"];
self.videoViewController.city.camera= self.city.camera;
[self.navigationController pushViewController:self.videoViewController animated:YES];
}
#end
As a test I inserted NSLog(#"%#", see); into the IBAction method but this is not returning any value
DetailController.h
#import <UIKit/UIKit.h>
#import "VideoController.h"
#import <Social/Social.h>
#class City;
#interface DetailController : UIViewController {
IBOutlet UIScrollView *scroller;
}
#property (weak, nonatomic) IBOutlet UIBarButtonItem *taxi;
#property (strong,nonatomic) City *city;
#property (weak, nonatomic) IBOutlet UILabel *ClubName;
#property (weak, nonatomic) IBOutlet UILabel *Vip;
#property (weak, nonatomic) IBOutlet UILabel *Price;
#property (nonatomic, strong)NSString * camera;
#property (weak, nonatomic) IBOutlet UILabel *Promo;
#property (weak, nonatomic) IBOutlet UILabel *remain;
#property (weak, nonatomic) IBOutlet UILabel *p;
#property (weak, nonatomic) IBOutlet UILabel *deal;
#property (weak, nonatomic) IBOutlet UILabel *money;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *tweet;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *post;
- (IBAction)line:(id)sender;
#end
Thanks for any suggestions on why this method is not being called when the button is pushed
The only way for your IBAction to NOT get called is when the button is not appropriately connected to it. Double check that in the connections inspector.

How to save UIImages in view

In my app I have two views: a mapView, and a detail view. The mapView has annotations, and the annotation views have right callout buttons that push the detail view onto the stack when the callout button is pressed. In the detail view, the user can take a picture that appears on the UIImage that is on the detail view controller. What I want is for a different image to be on the detail view controller for each annotation. I have read that I can use a singleton, and I have made a singleton class, but I do not know how to use it. Can someone help me out?
Here is some code:
My MKAnnotation class:
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
#interface MapPoint : NSObject <MKAnnotation>
{
NSString *_address;
CLLocationCoordinate2D _coordinate;
NSNumber *_identifier;
UIImage *_image;
}
- (id)initWithAddress:(NSString*)address
coordinate:(CLLocationCoordinate2D)coordinate
title:(NSString *)t
identifier:(NSNumber *)ident;
//This is a required property from MKAnnotation
#property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
//This is an optional property from MKAnnotataion
#property (nonatomic, copy) NSString *title;
#property (nonatomic, readonly, copy) NSString *subtitle;
#property (nonatomic) BOOL animatesDrop;
#property (nonatomic) BOOL canShowCallout;
#property (copy) NSString *address;
#property (copy) NSNumber *identifier;
#property (copy,nonatomic) UIImage *image;
#end
#implementation MapPoint
#synthesize title, subtitle, animatesDrop, canShowCallout;
#synthesize address = _address, coordinate = _coordinate, identifier = _identifier, image = _image;
-(id)initWithAddress:(NSString *)address
coordinate:(CLLocationCoordinate2D)coordinate
title:(NSString *)t
identifier:(NSNumber *)ident
{
self = [super init];
if (self) {
_address = [address copy];
_coordinate = coordinate;
_identifier = ident;
[self setTitle:t];
NSDate *theDate = [NSDate date];
subtitle = [NSDateFormatter localizedStringFromDate:theDate
dateStyle:NSDateFormatterMediumStyle
timeStyle:NSDateFormatterMediumStyle];
}
return self;
}
#end
Here is the detail view controller:
#import <UIKit/UIKit.h>
#class P2OViewController;
#interface PinViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate,UITextFieldDelegate>
{
__weak IBOutlet UILabel *label;
__weak IBOutlet UIButton *removeButton;
NSString *addressForLabel;
__weak P2OViewController *_vc;
__weak NSNumber *_identifier;
}
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#property (weak, nonatomic) IBOutlet UILabel *label;
#property (weak, nonatomic) IBOutlet UIButton *removeButton;
#property (weak, nonatomic) P2OViewController *vc;
#property (weak, nonatomic) NSNumber *identifier;
-(void)takePicture:(id)sender;
-(void)buttonPressed:(id)sender;
#end
#import "PinViewController.h"
#import "MapPoint.h"
#import "P2OViewController.h"
#implementation PinViewController
#synthesize imageView, label, removeButton;
#synthesize vc = _vc, identifier = _identifier;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
UIBarButtonItem *pic = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera
target:self
action:#selector(takePicture:)];
[[self navigationItem]setRightBarButtonItem:pic];
}
return self;
}
-(void)takePicture:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc]init];
//If our device has a camera, we ant to take a picture, otherwise, we just pick from photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
} else {
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
[imagePicker setDelegate:self];
//Place the image picker on the screen
[self presentViewController:imagePicker
animated:YES
completion:nil];
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//Get picked image from info dictionary
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
//Put the image onto the screen in out image view
[imageView setImage:image];
//Take image picker off the screen - you must call this dismiss method
[self dismissViewControllerAnimated:YES
completion:nil];
}
#end
You surely have a class implementing the MKAnnotation protocol.
In this class simply add a UIImage property and assign to every annotation its custom image.
Then when presenting the detailed view you just pass around the annotation and access its image property you defined.
EDIT
In your PinViewController simply declare a property like this
#property(nonatomic, strong) MapPoint * annotation;
Before you present your PinViewController assign the corresponding annotation to it, doing something like
detailedController.annotation = theAnnotation;
Do whatever you need to do to get the image, then store it in the annotation in this way
self.annotation.image = theImage;
Now the annotation is storing the image, so as long as you keep it in memory it will be there available for you.
The next time you push the detailed view you can perform a check to see whether that annotation has already an image or not
if(nil != self.annotation.image) {
// do something
} else {
// do something else
}

Why can't I add a UIScrollView to a UIImageView (with it working properly)

I'm working on an app. Here I describe a simplified version of a strange problem I am experiencing.
I have a storyboard created View Controller with a UIImageView also created in the storyboard.
I then have the following h and m files which aim to add a UIScrollView to the UIImageview and give the scrollview a container.
h file:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIImageView *imageView;
#property (nonatomic, strong) UIScrollView* scrollView;
#property (nonatomic, strong) UIView* container;
#end
m file:
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage *image = [UIImage imageNamed: #"new_phots_fake_port.png"];
//Add the image to the imageView I created in the Storyboard
[_imageView setImage:image];
_scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(60.0, 70.0, 522.0, 100.0)];
[_scrollView setBackgroundColor:[UIColor yellowColor]];
// Set up the container view to exist inside the scrollview:
CGSize containerSize = CGSizeMake(5000.0f, 730.0f);
_container = [[UIView alloc] initWithFrame:(CGRect){.origin=CGPointMake(0.0f, 0.0f), .size=containerSize}];
_container.backgroundColor = [UIColor redColor];
// Tell the scroll view the size of the contents
self.scrollView.contentSize = containerSize;
[_scrollView addSubview:_container];
[_imageView addSubview:_scrollView]; //This is what I want but doesn't allow scrolling
//[self.view addSubview:_scrollView]; //This allows scrolling but makes the imageView and Scrollview siblings. I need scrollview to be a child of imageview
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
So, the scrollview cannot seem to be added to the imageview (and function correctly). Why? What am I doing wrong?
Strangely, I also didn't use either of the delegate methods viewForZoomingInScrollView or scrollViewDidZoom. I'm not sure why these were not needed.
You need to set userInteractionEnabled on the UIImageView
_imageView.userInteractionEnabled = YES;

Change size of View in UYLModalViewController

I create an modal View controller. And In I crate TableView And TextField
In vertical position all ok!
Verticlal
But in horizontal a can see all of this
How can I resize my view for it?
Here the code of call ModalView
-(IBAction)buttonTapped:(id)sender{
UYLModalViewController *modalVC = [[UYLModalViewController alloc] initWithNibName:#"UYLModalViewController" bundle:nil];
modalVC.delegate = self;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:modalVC];
if (modalViewShowType==1)
{
nc.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:nc animated:YES];
}
else{
nc.modalPresentationStyle = UIModalPresentationFormSheet;
nc.view.bounds = CGRectMake(0, 0, 320, 480);
[self presentModalViewController:nc animated:YES];
//nc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//nc.view.frame = CGRectMake(0, 0, 320, 480);//it's important to do this after presentModalViewController
//nc.view.center = self.view.center;
}
[modalVC release];
[nc release];
}
and here the declaration of controller for modalView
#protocol UYLModalViewControllerDelegate
-(void) buttonDonePassed :(NSArray *) variables;
#end
#interface UYLModalViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>
{
id<UYLModalViewControllerDelegate> delegate;
//id<UITextFieldDelegate> textdelegate;
// id<UITextField> txt;
IBOutlet UITableView *tblView;
IBOutlet UITextField *textField;
NSMutableArray *cellsArray;
BOOL isAddedNewRow;
//UITextField *textField;
}
- (UITableViewCell *) getCellContentView:(NSString *)cellIdentifier :(NSInteger *)cellRow;
//-(void) clickToTextField:(id)sender;
#property (nonatomic, assign) id<UYLModalViewControllerDelegate> delegate;
#property (nonatomic, retain) IBOutlet UITableView *tblView;
#property (retain, nonatomic) IBOutlet UITextField *textField;
#end
As I can see in debug mode when the device in horizontal position it doesn't go to the tableview delegate methods =(
1) Where is defined the methode :
-(IBAction)buttonTapped:(id)sender;
I think that there is a problem with presenting modal a viewController over an
UISplitViewController...try to present it over an other ViewController to test
2) the UISplitViewController can create some problems if you use it not correctly
example: try to addSubView its view ( you can't push it )
3) Verify with the auoresizeMask of UYLModalViewController view

if statement not working

I have an app where there is a timer. It goes from 10 to 0. Using NSTimer. I have said:
.m:
//
// Skin.m
// PopThatPimple
//
// Created by Rohan Kapur on 6/2/11.
// Copyright 2011 UWCSEA. All rights reserved.
//
#import "Skin.h"
#implementation Skin
#synthesize theAudio;
#synthesize label;
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *myTouch = [touches anyObject];
CGPoint point = [myTouch locationInView:pimple];
if ( CGRectContainsPoint(pimple.bounds, point) ) {
[self checkcollision];
}
}
-(void)checkcollision {
pimple.center = CGPointMake(
random() % (unsigned int)theview.bounds.size.width,
random() % (unsigned int)theview.bounds.size.height
);
score.text = [NSString stringWithFormat:#"%d", ([score.text intValue] + 1)];
sad.hidden = NO;
NSURL* popURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"pop" ofType:#"mp3"]];
AudioServicesCreateSystemSoundID((CFURLRef) popURL, &popID);
AudioServicesPlaySystemSound(popID);
}
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
-(void)showActivity{
int currentTime = [time.text intValue];
int newTime = currentTime + -1;
time.text = [NSString stringWithFormat:#"%d", newTime];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
-(void)viewDidLoad {
myTicker = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector (showActivity) userInfo:nil repeats:YES];
[label2 setHidden:YES];
[super viewDidLoad];
}
-(void)void2 {
if ([label3.text isEqualToString:#"0"]) {
[[self view] addSubview:timeup];
score.text = label2.text;
label2.hidden = NO;
}
}
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
-(void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
-(void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
.h:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioToolbox.h>
#interface Skin : UIViewController {
IBOutlet UIImageView *pimple;
IBOutlet UIImageView *smile;
IBOutlet UIImageView *sad;
AVAudioPlayer *theAudio;
IBOutlet UIView *theview;
SystemSoundID popID;
IBOutlet UIImageView *face;
IBOutlet UIImageView *face2;
IBOutlet UIImageView *face3;
IBOutlet UIImageView *face4;
IBOutlet UIImageView *face5;
IBOutlet UIImageView *face6;
IBOutlet UIImageView *face7;
IBOutlet UIImageView *face8;
IBOutlet UIImageView *face9;
IBOutlet UIImageView *face10;
IBOutlet UIImageView *face11;
IBOutlet UIImageView *face12;
IBOutlet UIImageView *face13;
IBOutlet UIImageView *face14;
IBOutlet UIImageView *face15;
IBOutlet UILabel *label2;
IBOutlet UILabel *score;
IBOutlet UIImageView *skin;
IBOutlet UILabel *time;
NSTimer * myTicker;
IBOutlet UILabel *label3;
IBOutlet UIImageView * timeup;
}
-(IBAction)start;
-(void)void2;
-(void)showActivity;
#property (nonatomic, retain) UILabel *label;
#property (nonatomic, retain)AVAudioPlayer *theAudio;
-(void)checkcollision;
#end
I have not used all of my outlets and ibactions yet. And i have not used avfoundation yet
I have CONNECTED EVERYTHING! I HAVE CHECKEED A THOUSAND TIMES! When it reaches zero nothing happens and the timer just goes to the negatives. WHat am I doing wrong?
There are two major problems here, the first is you're using an assignment operator, not a comparison operator, I'd imagine you have a warning on that.
The second is an == comparison is useless here, the fixed code would be.
if ([label3.text isEqualToString:#"0"])
I'll second (third?) what #BoltClock and #Joshua Weinberg wrote, but add that checking the text displayed in a label is a poor way to determine whether a timer has expired. At some point, somewhere in your program, you're setting the label's text to #"0", so you already know that that condition is true. Likewise with the score... your controller should know what the score is, and it definitely shouldn't be relying on a label to get it.
Don't store data in your view objects. Data should flow from your model through your controller to your view. It only flows in the opposite direction when you're accepting user input.