我有一个方法启动,它连接到IB中的一个按钮,基本上,我第一次运行它,一切正常,但是当我第二次运行它时(我保证你没有其他任何事情发生在数据上)在之间),我在第一个循环(int i)之后得到一个EXC_BAD_ACCESS。我打开NSZombieEnabled并没有告诉我任何事情,我只是简单地得到一个简单的
收到信号: “EXC_BAD_ACCESS”。 sharedlibrary apply-load-rules all
以下是方法:
- (IBAction)start:(id)sender {
NSLog(@"1");
NSArray* firstArr = [data objectAtIndex:0];
NSLog(@"2");
for (int i=1; i < [data count]; i++) {
NSLog(@"%@", data);
NSArray* currArray = [data objectAtIndex:i];
NSString* fileName = [currArray objectAtIndex:[firstArr indexOfObject:@"UseFile"]];
NSString* filePath = [NSString stringWithFormat:@"/%@", fileName];
NSString* saveAs = [currArray objectAtIndex:[firstArr indexOfObject:@"SaveFileAs"]];
NSLog(@"3");
for (int j=0; j < [firstArr count]; j++) {
NSLog(@"4");
if ([self isIndexIdentifier:j]) {
NSLog(@"5");
NSString* searchStr = [firstArr objectAtIndex:j];
NSString* replaceStr = [currArray objectAtIndex:j];
NSDictionary* error;
NSLog(@"6");
NSString* appleScript = [NSString stringWithFormat:
@"set searchstring to \"%@\"\n"
@"set replacestring to \"%@\"\n"
@"tell application \"QuarkXPress\"\n"
@"activate\n"
@"if (not (exists document \"%@\")) then\n"
@"open POSIX file \"%@\" with Suppress All Warnings\n"
@"end if\n"
@"tell document \"%@\"\n"
@"repeat with tb from 1 to count of text box\n"
@"tell text box tb\n"
@"set (every text where it is searchstring) to replacestring\n"
@"end tell\n"
@"end repeat\n"
@"end tell\n"
@"end tell\n",
searchStr, replaceStr, fileName, filePath, fileName];
NSLog(@"7");
NSLog(@"%@", appleScript);
NSLog(@"8");
NSAppleScript *script = [[NSAppleScript alloc] initWithSource: appleScript];
NSLog(@"9");
[script executeAndReturnError:&error];
NSLog(@"10");
[script release];
NSLog(@"11");
NSLog(@"%@", error);
}
}
}
}
我NSLogged它,看看是否可以找到一些东西,这是控制台第二次调用该方法:
run
2011-04-02 08:55:38.145 TestUI[4472:a0f] 1
2011-04-02 08:55:38.145 TestUI[4472:a0f] 2
2011-04-02 08:55:38.146 TestUI[4472:a0f] (
(
UseFile,
xxxxxxxxxxxxx,
SaveFileAs
),
(
"1.qxp",
11111,
""
),
(
"2.qxp",
aslkvknv,
""
),
(
"3.qxp",
ABCDEFG,
""
),
(
"4.qxp",
222222222,
""
),
(
"5.qxp",
asdf,
adsffdsa
)
)
2011-04-02 08:55:38.146 TestUI[4472:a0f] 3
2011-04-02 08:55:38.147 TestUI[4472:a0f] 4
2011-04-02 08:55:38.147 TestUI[4472:a0f] 4
2011-04-02 08:55:38.147 TestUI[4472:a0f] 5
2011-04-02 08:55:38.147 TestUI[4472:a0f] 6
2011-04-02 08:55:38.148 TestUI[4472:a0f] 7
2011-04-02 08:55:38.148 TestUI[4472:a0f] set searchstring to "xxxxxxxxxxxxx"
set replacestring to "11111"
tell application "QuarkXPress"
activate
if (not (exists document "1.qxp")) then
open POSIX file "/1.qxp" with Suppress All Warnings
end if
tell document "1.qxp"
repeat with tb from 1 to count of text box
tell text box tb
set (every text where it is searchstring) to replacestring
end tell
end repeat
end tell
end tell
2011-04-02 08:55:38.148 TestUI[4472:a0f] 8
2011-04-02 08:55:38.148 TestUI[4472:a0f] 9
2011-04-02 08:55:38.517 TestUI[4472:a0f] 10
2011-04-02 08:55:38.517 TestUI[4472:a0f] 11
Program received signal: “EXC_BAD_ACCESS”.
sharedlibrary apply-load-rules all
(gdb)
答案 0 :(得分:3)
您的最终NSLog(error
)可能正是您粘贴的输出中崩溃的内容。 errorInfo
executeAndReturn:
参数的文档说:
返回时, 如果发生错误 ,指向错误信息字典的指针。
(重点补充)。因此,如果没有错误,则无法保证未初始化的error
变量不是垃圾指针。
答案 1 :(得分:0)
您是否尝试使用Zombies Instrument运行应用程序?
您的问题很可能是data
的过度释放,而且乐器应该发现这一点
如果弹出“Zombie Detected”消息,请单击内存地址并显示扩展详细信息面板。 (查看→扩展细节)