由于添加视差图像而未被调用的方法

时间:2014-07-03 19:45:18

标签: ios objective-c xcode methods delegates

所以我最近在我的app中实现了视差图像效果很好,但这打破了一个调用方法的按钮。

这是我的故事板的图片:

http://imgur.com/uIonWrK

这是我的.h代码:

@interface _01FirstViewController : UIViewController <UITextFieldDelegate, UIAccelerometerDelegate>{

UIAccelerometer *accelerometer;
float xoof;
float yoff;
float xvelocity;
float yvelocity;
float xaccel;
float yaccel;
}

@property (nonatomic, retain) UIAccelerometer *accelerometer;
@property (weak, nonatomic) IBOutlet UIScrollView *BGScrollView;
@property (weak, nonatomic) IBOutlet UIButton *Track;
@property (weak, nonatomic) IBOutlet UITextField *trackingNumber;
@property (strong, nonatomic) NSDictionary *posts;
@property (strong,nonatomic) NSString *TrackPoint;
@property (strong,nonatomic) NSArray *Path;
@property (strong,nonatomic) NSString *documentFolder;
@property (strong,nonatomic) NSString *filePath;

-(void)parseTrackNo;
-(void)reloadTrackingNumber;

以下是.m:

的相关部分
- (void)viewDidLoad
{
_BGScrollView.contentSize =      CGSizeMake(_BGScrollView.frame.size.width+30,_BGScrollView.frame.size.width+30);
self.accelerometer = [UIAccelerometer sharedAccelerometer];
self.accelerometer.updateInterval = 0.03;
self.accelerometer.delegate = self;

[NSTimer scheduledTimerWithTimeInterval:-1 target:self selector:@selector(tick) userInfo:nil   repeats:YES];
}

-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration{
float xx = -acceleration.x;
float yy = (acceleration.y + 0.5f) *2.0f;
float acceldirX;
if (xvelocity * -1.0f >0){
    acceldirX = 1.0;
}
else {
    acceldirX = -1.0;
}


float newdirX;
if (xx > 0){
    newdirX = 1.0;
}
else {
    newdirX = -1.0;
}

float acceldirY;
if (yvelocity * -1.0f >0){
    acceldirY = 1.0;
}
else {
    acceldirY = -1.0;
}

float newDirY;
if (yy > 0){
    newDirY = 1.0;
}
else {
    newDirY = -1.0;
}

if (acceldirX == newdirX) xoof = acceleration.x * 30;
if (acceldirY == newDirY) yoff = acceleration.y *30;
}

这是停止调用方法的按钮:

- (IBAction)Track:(id)sender {
[self parseTrackNo]; //Not calling method
NSLog(@"Button Pressed"); //This gets logged correctly

}

我已经尝试删除所有代码更改,因此我怀疑它与嵌套在storyboard视图中的按钮或代理更改有关。

有人能指出我正确的方向吗?

按要求编辑parseTrackingNo的代码(注意这是完美的,直到视差改变):

-(void)parseTrackNo
{

    _01AppDelegate *appDelegate = (_01AppDelegate *)[[UIApplication sharedApplication] delegate];

    //Get Tracking Number from textField
    appDelegate.TrackingNumber = _trackingNumber.text;

    //Check String isn't empty
    if ([_trackingNumber.text  isEqual: @""]){

    } else{

        //Check against Royal Mail API
        NSString *trackingURL = [NSString stringWithFormat:@"%@%@",   @"http://api.e44.co/tracktrace/", appDelegate.TrackingNumber];

        NSURL *royalMail = [NSURL URLWithString:trackingURL];

        //Return results
        NSData *royalMailResults = [NSData dataWithContentsOfURL:royalMail];

        //Parse JSON results
        if(royalMailResults != nil)
        {
            NSError *error = nil;
            id result = [NSJSONSerialization JSONObjectWithData:royalMailResults options:NSJSONReadingMutableContainers error:&error];
            if (error == nil)

            //Convert to dictionary/array
            self.posts = (NSDictionary *)result;
            NSArray *trackRecords = _posts[@"trackRecords"];

            //Return keys from posts (Dict)
            NSString *response = [self.posts valueForKeyPath:@"response"];
            NSLog(@"Response: %@", response);

            NSString *returnedTrackingNumber = [self.posts valueForKeyPath:@"trackingNumber"];
            NSLog(@"Returned tracking number: %@", returnedTrackingNumber);

            NSString *delivered = [self.posts valueForKeyPath:@"delivered"];
            NSLog(@"delivered: %@", delivered);

            NSString *signature = [self.posts valueForKeyPath:@"signature"];
            NSLog(@"Signature: %@", signature);


            //Track Records
            NSString *Date = [trackRecords valueForKeyPath:@"date"];
            NSLog(@"date: %@", Date);

            NSString *Time = [trackRecords valueForKeyPath:@"time"];
            NSLog(@"time: %@", Time);

            NSString *Status = [trackRecords valueForKeyPath:@"status"];
            NSLog(@"status: %@", Status);

            appDelegate.LocationData = [[trackRecords valueForKey:@"trackPoint"] componentsJoinedByString:@""];
            NSLog(@"GeoLocation: %@", appDelegate.LocationData);


            //Check for Errors returned
            if ([self.posts objectForKey:@"errorMsg"]) {
                NSLog(@"ERROR MOTHERFUCKER");
                UIAlertView *alert = [[UIAlertView alloc]

                initWithTitle:@"Error"
                message:@"It appears that you have entered an incorrect tracking number"
                delegate:self
                cancelButtonTitle:@"OK"
                otherButtonTitles:nil, nil];
                [alert show];
            } else {
                [self performSegueWithIdentifier:@"addPackageSegue" sender:self];
            }
        }

    }
}

0 个答案:

没有答案