在iOS练习中,我新建立了一个NSObject
类JQCellStruct
,声明了double
类型的成员变量p
和a
,在ViewController
中生成了数次类的对象str
,分别赋值了a的值,使用addObject:
方法添加进了可变数组sarray
中。
如果我现在想用stringWithFormat:
方法,令某个label
显示出数组的第i
个str
对象中p
的数值,应该怎么取得p
?
试了点语法和其他网上找的方法,都报错了,希望能够得到解答,谢谢!
添加语句是:
JQCellStruct *str = [[JQCellStruct alloc] init];
str.p = &(dPrice);
str.a = &(dAmount);
[_sarray addObject:str];
实际在程序中报错的语句是在tableView cellForRowAtIndexPath
方法下的:
NSString *p = [NSString stringWithFormat:@"%ld",(long)_sarray[indexPath.row].p];
错误信息为:Property 'p' not found on object of type 'id'
是 Objc 还是 swift?
swift: