-2

所以我有一个类,此时只包含一个简单的 NSMutableArray 对象。我正在从视图控制器设置这个对象,但由于某种原因......愚蠢的东西在我的 ipad 上不起作用。然而,它在模拟器上完美运行。

有没有人遇到过这种情况?

我知道这不是很多事情要做,但任何关于在哪里看的提示/指针都会有所帮助。不知道在这个上搜索什么。

谢谢


视图控制器.h

#import "DBEntries.h"
DBEntries *dbEntries;

视图控制器.m:

[database open];

NSMutableArray *arrayAdder = [[NSMutableArray alloc] init];

NSString *filterNameFirst = [NSString stringWithFormat:@"%@", nameFirstTextField.text];
NSString *filterNameLast = [NSString stringWithFormat:@"%@", nameLastTextField.text];

NSString *filterStringFirst = [NSString stringWithFormat:@"%%%@%%", filterNameFirst]; // Works on first name only.
NSString *filterStringLast = [NSString stringWithFormat:@"%%%@%%", filterNameLast]; // Works on last name only.

FMResultSet *results = [database executeQuery:[NSString stringWithFormat:@"SELECT * FROM users WHERE firstname LIKE ? AND lastname LIKE ?", filterStringFirst, filterStringLast]];

while([results next])
{
    NSString *firstname = [results stringForColumn:@"firstname"];
    NSString *lastname = [results stringForColumn:@"lastname"];

    // Add db entries to array in DBEntries.
    NSString *objectAdder = [NSString stringWithFormat:@"%@ %@", firstname, lastname];
    NSLog(@"objectAdder: %@", objectAdder);
    [arrayAdder addObject:objectAdder];
}

[dbEntries setUsersFiltered:arrayAdder];
[arrayAdder release];

[database close];

isUpdatingEntriesForTableView = YES;

[dbTableView reloadData];

NSLog(@"dbEntries.usersFiltered: %@", dbEntries.usersFiltered); // This logs 0 on device, but works on simulator.

类.h:

NSMutableArray *usersFiltered;
@property (strong, nonatomic) NSMutableArray *usersFiltered;

类.m:

@synthesize usersFiltered;
4

2 回答 2

1

我不使用strong进行自动内存计数,我只是不喜欢它。你有没有尝试过

@property (retain, nonatomic) NSMutableArray *usersFiltered;

您可以替换以下行:

[dbEntries setUsersFiltered:arrayAdder];
[arrayAdder release];

和:

dbEntries.usersFiltered = [arrayAdder autorelease];
//[arrayAdder release];
于 2012-08-05T05:05:01.557 回答
0

哇。好的,所以答案与@omz 的观点有关。我不应该使用 [NSString stringWithFormat]。删除它FMResultSet *results = [database executeQuery:@"SELECT * FROM users WHERE firstname LIKE ? AND lastname LIKE ?", filterStringFirst, filterStringLast];现在不会触发警告并在设备上工作。有趣的是,它可以在模拟器上运行,但之前不能在设备上运行。

于 2012-08-05T17:49:01.463 回答