【问题标题】:Xcode need help merging GPS project, Accelerometer project, Compass project and MySQL projectXcode 需要帮助合并 GPS 项目、Accelerometer 项目、Compass 项目和 MySQL 项目
【发布时间】:2013-01-14 11:58:29
【问题描述】:

我有 4 个 Xcode 项目(GPS、加速度计、指南针和 MySQL)。

他们每个人都单独编译并且工作正常。

我想将所有这些组合到一个项目中,这样我就可以将 GPS、加速度计和指南针信息发送到 mySQL 数据库。

我尝试将.h.m 以及项目所需的框架复制到另一个项目。

问题主要出现在这里:

- (IBAction)insert:(id)sender
{
    // create string contains url address for php file, the file name is phpFile.php, it receives parameter :name
    //NSString *strURL = [NSString stringWithFormat:@"http://localhost/phpFile.php?name=%@",txtName.text];
    NSString *strURL = [NSString stringWithFormat:@"http://localhost/phpFile.php?name=%@",speedLabel.text]; ************<   use of undefined identifier 'speedLabel'****

    // to execute php code
    NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:strURL]];

    // to receive the returend value
    NSString *strResult = [[[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding]autorelease];

    NSLog(@"%@", strResult);
}

这是包含 speedLabel 的结构:

@interface CoreLocationDemoViewController : UIViewController <CoreLocationControllerDelegate> {
    CoreLocationController *CLController;
    IBOutlet UILabel *speedLabel;
    IBOutlet UILabel *latitudeLabel;
    IBOutlet UILabel *longitudeLabel;
    IBOutlet UILabel *altitudeLabel;
    IBOutlet UILabel *timeLabel;
}

感谢您的帮助

【问题讨论】:

  • 有什么问题?还是您希望我们为您复制所有 MySQL 代码?
  • 嗨,不,我的问题是我无法访问下的 speedLabel 变量: NSString *strURL = [NSString stringWithFormat:@"localhost/phpFile.php?speedLabel=%@",speedLabel.text]; 当我尝试在我的代码中出现错误说使用未定义的标识符 speedLabel。感谢 Regisma

标签: mysql xcode gps accelerometer compass-geolocation


【解决方案1】:

您是否正在导入您的 .h 文件:

#import "CoreLocationDemoViewController.h"

我看不出你的代码有任何缺陷。

该代码是否在@implementation@end 范围内调用?您是否将其声明为财产,然后@synthesize

【讨论】:

  • 嗨,mySQL 的接口在 ConnectToDBAppDelegate.h 下,语句 NSString *strURL = [NSString stringWithFormat:@"localhost/phpFile.php?name=%@",speedLabel.text]; 在 ConnectToDBAppDelegate.m 下 GPS 信息在 CoreLocationDemoViewController.h 下并且 speedLabel 的 @synthesize 在 CoreLocationDemoViewController.m 下。在 ConnectToDBAppDelegate.m 下我确实导入了 CoreLocationDemoViewController.h 谢谢 Regis
【解决方案2】:

为了查看来自 GPS 接口的变量,我确实使用了我在 stackoverflow 某处找到的以下技术:

// Globals.h
#ifndef Globals_h
#define Globals_h

extern NSInteger globalVariable;

#endif

// main.m 

NSInteger globalVariable;

int main(int argc, char *argv[])
{
   globalVariable = <# initial value #>;
    ...
}

// Prefix.pch

#ifdef __OBJC__
    #import 
    #import <Foundation/Foundation.h>
    #import "Globals.h"
#endif

我确实使用了这项技术:

NSString *strURL = [NSString stringWithFormat:@"http://localhost/phpFile.php?name=%@",speedLabel.text];

将信息发送到mysql数据库。

但我还是需要一点帮助。

我有一个用于 GPS 的接口,另一个用于加速度计,另一个用于指南针。如何调用它们中的每一个,以便我可以通过单击 Iphone 上的一个按钮将相关数据存储到它们中?

非常感谢

注册表

【讨论】:

  • 嗨,如果我想从另一个接口(例如加速度计)访问数据,这个技巧似乎不起作用。你能指导我吗?谢谢雷吉斯
猜你喜欢
  • 2012-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-13
  • 2011-03-26
  • 1970-01-01
  • 2020-05-18
相关资源
最近更新 更多