添加新对象时NSMutableArray奇怪地行为

时间:2015-09-15 22:05:34

标签: ios objective-c parse-platform nsmutablearray nsarray

我正在编写一个错误标识符应用程序,并将我的错误描述存储在一个将存储到Parse数据库的数组中。单个视图控制器将10个左右的错误传递给查看器。但是,当用户按下提交按钮时,阵列的行为非常奇怪。

- (IBAction)addOrSubmitPressed:(id)sender {
if ([_bugCountLabel.text integerValue] > totalBugs) {
    pickerStatus = New;
    [self showPickerFor:pickerStatus];

} else if ([_bugCountLabel.text integerValue] == totalBugs) {
    // Save values to the current identity
    SFBugIdentity *identity = [cardData objectAtIndex:index];
    identity.stringsOfBugs = tableViewCells;
    identity.totalBugs = totalBugs;
    [cardData replaceObjectAtIndex:index withObject:identity];
    NSLog(@"Added a card with %li total bugs, %lu strings.", (long)identity.totalBugs, (unsigned long)identity.stringsOfBugs.count);
    [bugStrings addObject:identity.stringsOfBugs];
    NSLog(@"%@", identity.stringsOfBugs);
    NSLog(@"%@", bugStrings);

    // Reset all values (a bit sloppy atm...)
    [tableViewCells removeAllObjects];
    totalBugs = 0;
    [_tableView reloadData];

    // Load the next item in the array, if there is one. Otherwise shoot up to Parse and dismiss this view controller
    index++;

大。所以首先,日志将会读出:

2015-09-15 17:57:09.459 PestCap[43286:455596] (
    "1 x Gnat"
)
2015-09-15 17:57:09.460 PestCap[43286:455596] (
        (
        "1 x Gnat"
    )
)

但是,当我添加另一个对象时,会发生这种情况:

2015-09-15 18:03:56.148 PestCap[43286:455596] Added a card with 2 total 

bugs, 2 strings.
2015-09-15 18:03:56.148 PestCap[43286:455596] (
    "1 x Gnat",
    "1 x House Fly"
)
2015-09-15 18:03:56.148 PestCap[43286:455596] (
        (
        "1 x Gnat",
        "1 x House Fly"
    ),
        (
        "1 x Gnat",
        "1 x House Fly"
    )
)

发生了什么事? bugStrings在@implementation中,在ViewDidLoad中分配,并且在我向其添加对象时仅被调用(此外,当我访问对象以存储到Parse时,但此时此代码未执行)。

编辑:其他信息:tableViewCells是NSStrings的NSMutableArray,我用它作为视图控制器上表的数据源。 totalBugs是一个全局变量,无论何时提交卡都会重置。

0 个答案:

没有答案