简体   繁体   English

使用来自另一个类的值的Objective-c NSArray

[英]Objective-c NSArray with values from another class

I am trying to create a table view in my view based application but I am facing a problem 我正在尝试在基于视图的应用程序中创建表视图,但遇到了问题

NSArray *array = [[NSArray alloc] initWithObjects:@"iPod",forecast.desc,nil];
NSLog(@"this is the forecast routeNo = %@", forecast.desc);

As you can see this is the array that shows the values in the table, the result of this code is iPod (only), "forecast.desc" doesn't show anything knowing that forecast is an instance of another class and "desc" is a string in that class 如您所见,这是显示表中值的数组,此代码的结果是iPod(仅),“ forecast.desc”不会显示任何内容,因为它知道预测是另一个类的实例,而“ desc”是该类中的字符串

and just to make sure forecast.desc shows the correct information in the log but in the table as if doesn't exist can anyone see where is the problem ? 并只是为了确保Forecast.desc在日志中显示正确的信息,但在表中好像不存在一样,没有人可以看到问题出在哪里吗?

Thanks 谢谢

尝试

[[NSArray alloc] initWithObjects:@"iPod", [NSString stringWithFormat:@"%@",forecast.desc], nil];

@bhappy the result of array variable is @"iPod" only means that forecast.desc has nil value. @bhappy数组变量的结果是@“ iPod”,仅表示Forecast.desc的值为nil。

So try to debug the code using single stepping and check what is the value of desc at the time of initializing the array. 因此,尝试使用单步调试代码,并在初始化数组时检查desc的值是什么。

And one more thing if desc is a member variable of class forecast than did you set the property for it, if not then forecast.desc wont work. 而且,如果desc是class Forecast的成员变量,则比您为其设置属性还要多,如果没有,则Forecast.desc无法正常工作。 You should check that first. 您应该先检查一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM