所以我有一个类,此时只包含一个简单的NSMutableArray对象。我正在从一个视图控制器设置这个对象,但出于某种原因......愚蠢的事情在我的ipad上不起作用。然而,它在模拟器上完美无缺。
有没有人遇到过这种情况?
我知道继续下去并不是很多,但任何关于在哪里寻找的提示/指示都会有所帮助。不知道在这个上搜索什么。
由于
ViewController.h
#import "DBEntries.h"
DBEntries *dbEntries;
ViewController.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.
class.h:
NSMutableArray *usersFiltered;
@property (strong, nonatomic) NSMutableArray *usersFiltered;
class.m:
@synthesize usersFiltered;
答案 0 :(得分:1)
我不使用强进行自动内存计数,我只是不喜欢它。你试过吗
@property (retain, nonatomic) NSMutableArray *usersFiltered;
您可以替换以下行:
[dbEntries setUsersFiltered:arrayAdder];
[arrayAdder release];
使用:
dbEntries.usersFiltered = [arrayAdder autorelease];
//[arrayAdder release];
答案 1 :(得分:0)
哇。好的,答案与@omz的观点有关。我当时不应该使用[NSString stringWithFormat。删除它所以它FMResultSet *results = [database executeQuery:@"SELECT * FROM users WHERE firstname LIKE ? AND lastname LIKE ?", filterStringFirst, filterStringLast];
现在不会触发警告并在设备上工作。有趣的是它之前在模拟器上工作但不是设备。