保存值的 xcode 全局 nsmutablearray
进行了搜索,但似乎无法准确找到我要找的东西 基本上我用一种方法将值加载到 nsmutablearray 中,然后我想用另一种方法访问这些值以将它们打印到表中 我在 app.h
NSMutableArray *clients;
中声明了该数组,然后在 app.m 中
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSArray *results = [responseString JSONValue];
clients = [[NSMutableArray alloc]init];
// Loop through each entry and add clients to array
for (NSDictionary *entry in results)
{
if (![clients containsObject:[entry objectForKey:@"client"]])
{
[clients addObject:[entry objectForKey:@"client"]];
}
}
}
声明了该数组现在我尝试用另一种方法访问客户端数组 我看到一些在 app.h 中使用 extern 的建议?某种全局变量?
任何帮助将不胜感激
谢谢
Did a search but cant seem to find exactly what I'm looking for
Basically I load values into a nsmutablearray in one method and then I want to access these values in another method to print them to a table
I declared the array in the app.h
NSMutableArray *clients;
Then in the app.m
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSArray *results = [responseString JSONValue];
clients = [[NSMutableArray alloc]init];
// Loop through each entry and add clients to array
for (NSDictionary *entry in results)
{
if (![clients containsObject:[entry objectForKey:@"client"]])
{
[clients addObject:[entry objectForKey:@"client"]];
}
}
}
Now Im try to acces the clients array in another method
I have seen some suggestions to use extern in the app.h? Some sort of global variable?
Any help would be appreciated
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在应用程序委托类中获取客户端数组。声明属性,在应用程序委托类中合成。然后在下面的方法中这样写。
YourApplicationDelegate *委托= [UIApplication共享应用]委托];
之后假设您如果想在另一个类中使用客户端数组,请这样做。
Take the clients array in app delegate class.declare the property,synthesizes in the app delegate class.Then in the below method write like this.
YourApplicationDelegate *delegate = [UIApplication sharedApplication]delegate];
after that suppose you if you want to use the clients array in another class do like this.