objective-c - 在 xcode 中显示数组

标签 objective-c arrays cocoa

我正在尝试显示具有不同数字因子(“质数”)的数组。但我总是得到 0,1,2,3,4,5,... 而不是给我 int 数字。

        factors.text = @"";

        int factorsNumber;

        NSMutableArray *array;
        array = [NSMutableArray arrayWithCapacity:5];

        for (factorsNumber=1; factorsNumber<=prime; factorsNumber++) {
            if (prime%factorsNumber == 0) {
                [array addObject:[NSString stringWithFormat:@"%d", factorsNumber]];
            }

        }


        for (int i = 0; i < [array count]; i++) {

            [array replaceObjectAtIndex:1 withObject:@"4"];

            NSString *temp = [NSString stringWithFormat:@"%d, ", i, [[array objectAtIndex:i] intValue]];
            factors.text = [factors.text stringByAppendingString:temp];
        }

最佳答案

替换

NSString *temp = [NSString stringWithFormat:@"%d, ", i, [[array objectAtIndex:i] intValue]];

NSString *temp = [NSString stringWithFormat:@"%d, ", [[array objectAtIndex:i] intValue]];

问题是您只打印数组索引,而不是值。

关于objective-c - 在 xcode 中显示数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11650370/

相关文章:

javascript - 来自地址数组的多个标记 Google Map API v3 并在 pageLoad 上进行地理编码时避免 OVER_QUERY_LIMIT

java - 尝试将字符串添加到一个字符串列表,但最终将字符串添加到两个字符串列表。

javascript - 如何遍历JSON数组?

objective-c - 覆盖粘贴: to format text

objective-c - 沙箱: How to bookmark enclosing folder of user-selected file?

iphone - iOS 数据文件允许文件安全、编码吗?

ios - WKWebView 可能发生崩溃

ios - 难以在 Xcode 中归档静态库(未找到)

iphone - 显示当前周的开始和结束日期

objective-c - 我怎么知道 NSTextView 何时失去焦点?