Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 当tableview从URL获取数据时,是否获取EXC\u错误访问权限?_Objective C_Ios_Uitableview_Exc Bad Access - Fatal编程技术网

Objective c 当tableview从URL获取数据时,是否获取EXC\u错误访问权限?

Objective c 当tableview从URL获取数据时,是否获取EXC\u错误访问权限?,objective-c,ios,uitableview,exc-bad-access,Objective C,Ios,Uitableview,Exc Bad Access,我的tableview是从URL获取XML数据,首先声明一个NSMutableArray*dataArray 这就是我在TableviewSample.m - (void)getDataFromURL{ NSString *theURLAsString = [NSString stringWithFormat:GetAllData];//<-EXE_BAD_ACCESS HERE //#define stringWithFormat:GetAllData @"http://19

我的tableview是从URL获取XML数据,首先声明一个
NSMutableArray*dataArray

这就是我在
TableviewSample.m

- (void)getDataFromURL{
   NSString *theURLAsString = [NSString stringWithFormat:GetAllData];//<-EXE_BAD_ACCESS HERE
   //#define stringWithFormat:GetAllData @"http://192.168.10.28/req_alldata.php"
   NSURL *theURL = [NSURL URLWithString:theURLAsString];
   self.dataArray = [NSMutableArray arrayWithContentsOfURL:theURL];
}

GetAllData
来自哪里?看起来这并没有指向任何东西。更多的代码、准确的错误和更仔细的描述将在这里起到很大作用。

这可能与使用#define有关,define没有说明所使用对象的类型。 如果要在代码中定义常量字符串,最好使用如下内容:

static NSString *GetAllData = @"192.168.10.28/req_alldata.php";
在需要使用字符串的地方,您可以简单地编写:

NSString *GoToWebCam = [NSString stringWithString:GetAllData];

GetAllData我创建一个.h文件并像这样声明它#定义GetAllData@“”,然后我导入.h,这就是我声明它的方式…它有帮助吗?尝试将它编码成stringWithFormat:,像这样:NSString*directGoToWebCam=[NSString stringWithFormat:@“192.168.10.28/req_alldata.php];这有用吗?嗯…我不知道这两个URL之间有什么不同…这真的重要吗?我尝试了你的解决方案,如果我在tableview和webview之间切换视图,它不会崩溃,但我的方式会崩溃…谢谢,但我想我遇到的另一个问题是使用bonjour搜索这个IP cam,所以IP地址应该是DHCP,它不是静态的…所以我想我需要一个新的解决方案…@WebberLai如果您编写一个名为“GetAllData”的方法,该方法使用Bonjour服务查找网络摄像头的IP,并返回和“NSString*”,则不必更改很多代码。
NSString *GoToWebCam = [NSString stringWithString:GetAllData];