IBAction按钮适用于iPhone 4s,但不适用于iPhone 5s

时间:2014-09-04 06:44:11

标签: ios iphone

我有一个IBAction按钮,可以在iPhone 4s上执行正确的代码。但是,当我在5s上测试时,按钮根本不起作用。该按钮出现在视图中,并在选中时突出显示,但它不会按预期将数据推送到服务器,就像4s一样。任何有关原因的见解?

- (IBAction)addLocation:(id)sender
{
    [self.locationButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

    [self createLocation];
    CLLocation *location = self.locationManager.location;
    if(!location)
    {
        return;
    }

    CLLocationCoordinate2D coordinate = [location coordinate];
    PFGeoPoint *geoPoint = [PFGeoPoint geoPointWithLatitude:coordinate.latitude     longitude:coordinate.longitude];
    PFObject *object = [PFObject objectWithClassName:@"Location"];
    [object setObject:geoPoint forKey:@"location"];
    [object setObject:self.recipient forKey:@"recipient"];

    [object saveEventually:^(BOOL succeeded, NSError *error) {
        if(succeeded){
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Your Location was sent!"message:[error.userInfo objectForKey:@"error"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

            [alertView show];
        }
    }];
}

修改

所以现在4s也没有用。我不确定这是好还是坏,但他们现在都在同一条船上。我不再被提示启用位置服务,因此可能存在问题。当我找到它时,我会发布解决方案。

编辑2

所以我终于让代码适用于两款iPhone。事实证明,首先初始化locationManager存在问题。这仍然无法解释为什么代码在短时间内与4s一起工作,但至少问题似乎现在已经解决了。

感谢所有提供可能解决方案的人!我感激你的时间!

3 个答案:

答案 0 :(得分:0)

您是否在为iPhone4s和iPhone5s使用单独的xib或故事板?如果是,请检查您的UIButton的IBAction是否已连接不是来自iPhone5s xib或故事板。 可能是IBAction与iPhone4s UI连接但不与iPhone5s UI连接。请重新检查一下。

答案 1 :(得分:0)

我曾经遇到过alertView的问题, 试试这个

[alertView performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES];
而不是     [alertView show];

答案 2 :(得分:0)

一些建议:

1)尝试检查您是否拥有location对象,以及在获取if对象后是否正在传递location语句。也许,在iPhone 5s位置服务被禁用,或者,您不允许您的应用使用位置服务?

2)在您PFObject实例的完成块中,尝试检查错误。也许,保存任务完成但有错误?

虽然这些建议不是您问题的答案,但它们可能会帮助您解决问题。 祝你好运!

相关问题