NSMutableArray * val;
val = [[NSMutableArray alloc] initWithCapacity:15];
/*int outlineWidth = barOutlineWidth;
int outlineHalfWidth = (outlineWidth > 1) ? outlineWidth * 0.5f : 0;
*/
for (Bar * obj in values)
{
// calcualte the bar size
float value = [obj value];
float scale = (value/maxValue);
// shift the bar to the top or bottom of the render line
int pointY = lineHeight + ((lineWidth * 0.5f) * ((value >= 0.0f) ? -1 : 1));
int barHeight = height * scale;
NSLog(@"%d", barHeight);
CGRect barRect = CGRectMake(pointX, pointY, width, -barHeight);
[val addObject:[NSNumber numberWithInt:barHeight]];
NSLog(@"%d", val);
Tôi muốn thêm độ cao (int) vào mảng val. Điều này có khả thi không? khi chạy mã,Làm thế nào để thêm một giá trị số nguyên vào NSMutableArray?
session started at 2010-09-16 13:21:50 +0530.]
2010-09-16 13:21:53.791 BarGraphSample[3168:20b] 78
2010-09-16 13:21:53.797 BarGraphSample[3168:20b] 69398112
2010-09-16 13:21:53.807 BarGraphSample[3168:20b] 235
2010-09-16 13:21:53.812 BarGraphSample[3168:20b] 69398112
2010-09-16 13:21:53.813 BarGraphSample[3168:20b] 156
2010-09-16 13:21:53.814 BarGraphSample[3168:20b] 69398112
đây là đầu ra.
Ở đây, độ cao thực tế là 78.235,156, trong khi in mảng val.
Tôi nhận được các giá trị như "69398112"
Tôi nên làm gì?
xOut sẽ là một NSNumber * không phải là một int, trừ khi bạn cũng truyền intValue cho đối tượng được trả về bởi lastObject. – jer
Cảm ơn bạn đã đánh bắt, cố định câu trả lời của tôi. –
Bởi "con trỏ", tôi nghĩ bạn có nghĩa là "đối tượng" - ví dụ: thêm một 'char *' sẽ vẫn yêu cầu gói nó lên trong một đối tượng. –