我怎样才能最容易地找到我的代码中的点(即"程序接收信号:EXC_BAD_ACCESS")被触发?
当我得到这个并且我在控制台中查看时,我没有看到任何其他信息,例如在这种情况下的堆栈跟踪.我知道我可以通过代码放置断点并尝试逐步找到,但是如果有一种方法可以更容易找到没有大量断点并且逐步完成那将是很好的.
编辑1 - 重新输入backtrace(重新回答这个问题),我看到了这一点,这似乎并没有突出我代码中的重点?
(gdb) backtrace
#0 0x00fd7a63 in objc_msgSend ()
#1 0x06019780 in ?? ()
#2 0x0046cf16 in -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] ()
#3 0x0046a9e7 in -[UITableViewRowData numberOfRows] ()
#4 0x003218c2 in -[UITableView noteNumberOfRowsChanged] ()
#5 0x0032e2b8 in -[UITableView reloadData] ()
#6 0x0032b470 in -[UITableView layoutSubviews] ()
#7 0x01d33451 in -[CALayer layoutSublayers] ()
#8 0x01d3317c in CALayerLayoutIfNeeded ()
#9 0x01d2c37c in CA::Context::commit_transaction ()
#10 0x01d2c0d0 in CA::Transaction::commit ()
#11 0x01d5c7d5 in CA::Transaction::observer_callback ()
#12 0x00e56fbb in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#13 0x00dec0e7 …Run Code Online (Sandbox Code Playgroud) 我有一个字符串变量存储日期选择器的日期,但是当我在其他函数中使用它的值时,我收到错误,如程序接收信号:"EXC_BAD_ACCESS".注意:变量是全局定义的.
代码:
- (void) changedDate: (UIDatePicker *) picker
{
if (appDelegate.dateint == 8)
{
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"dd MMM, yyyy"];
datestr=[dateFormatter stringFromDate:[dptpicker date]];
NSLog(@"date:%@",datestr);
}
else if(appDelegate.dateint == 9)
{ NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"dd MMM, yyyy"];
datestr1=[dateFormatter stringFromDate:[dptpicker date]] ;
NSLog(@"date1:%@",datestr1);
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个核心数据存储设置与Xcode生成的NSManagedObject的子类:注意.
我可以使用NSEntityDescription insertNewObjectForEntityName:inManagedObjectContext:没有问题,但是当我尝试这样做时:
NSManagedObjectContext* moc = [(QuickTextAppDelegate*)([[UIApplication sharedApplication] delegate]) managedObjectContext];
Note* note = [[Note alloc] initWithEntity:@"Note" insertIntoManagedObjectContext:moc];
Run Code Online (Sandbox Code Playgroud)
我收到一个EXC_BAD_ACCESS错误.
使用断点我可以看到NSManagedObjectContext*确实指向了一个有效的对象.
任何帮助,将不胜感激!
嘿人,我尝试为UIButtonTypeRoundedRect添加一个漂亮的渐变.以下代码在.中实现
viewWillAppear:(BOOL)animated
Run Code Online (Sandbox Code Playgroud)
我的视图控制器的功能.
UIButton *tempButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
tempButton.frame = CGRectMake(left, top, 80.0f, 80.0f);
CAGradientLayer * hintergrundButtonLayer = [[CAGradientLayer alloc] init];
[hintergrundButtonLayer setBounds:tempButton.bounds];
[hintergrundButtonLayer setColors:[NSArray arrayWithObjects:
[UIColor colorWithRed:0.2 green:0.3 blue:0.4 alpha:1.0],
[UIColor colorWithRed:0.4 green:0.5 blue:0.6 alpha:1.0],
nil]];
[hintergrundButtonLayer setPosition:
CGPointMake([tempButton bounds].size.width/2,
[tempButton bounds].size.height/2)];
[hintergrundButtonLayer setLocations:
[NSArray arrayWithObjects:
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:1.0],
nil]];
// hintergrundButtonLayer.zPosition = -10;
// hintergrundButtonLayer.frame = [tempButton bounds];
[tempButton addTarget:self action:@selector(switchVendorOnOff:) forControlEvents:UIControlEventTouchUpInside];
CALayer * downButtonLayer = [tempButton layer];
[downButtonLayer setMasksToBounds:YES];
[downButtonLayer setCornerRadius:10.0];
[downButtonLayer setBorderWidth:1.2];
[downButtonLayer setBorderColor:[[UIColor blackColor] …Run Code Online (Sandbox Code Playgroud) 如何在XCode4中启用NSZombiesEnabled?我曾经使用这个参数来调试XCode3中的EXC_BAD_ACCESS.不确定在XCode4中的位置.
在XCode 4.2中,我需要一些帮助,以跟踪EXC_BAD_ACCESS错误的原因.启用NSZombie标志后,当应用程序在设备上崩溃时,我在控制台上看到以下内容.
*** -[__NSArrayM removeObject:]: message sent to deallocated instance 0x8674e30
Run Code Online (Sandbox Code Playgroud)
我使用过Instruments,但没看到Zombie的个人资料.我使用了Allocations配置文件,但很快就输了.我为应用程序启用了ARC(希望摆脱alloc/retain/release) - 但仍然有同样的问题.
如何使用仪器跟踪此情况?
我是Objective-C编程的新手,当我运行我的小程序时,我收到此错误(我只想生成一个随机字符).所以这就是我到目前为止所做的:
(IBAction)generate{
int a = arc4random() % 26;
NSString * chaine = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char lettre = [chaine characterAtIndex:a];
NSMutableString * mot = [[NSMutableString alloc] initWithCharacters:lettre length:1];
hasard.text = mot;
}
Run Code Online (Sandbox Code Playgroud)
我试图简单地将我的变量'lettre'放在hasard.text中,但它不能用于错误'不兼容的整数到指针转换分配到' NSString *'来自' char'.所以我创建了一个NSMutableString包含我的角色.
当我在第五行手动输入字符"e"而不是变量"letter"时,它运行良好.因为我可以在调试器中看到'lettre'包含一个随机字母,为什么我会在标题中得到错误?
(EXC_BAD_ACCESS (code=2, address=0x42)).
在Xcode中使用C++我尝试使用MySQL Connector/C++访问MySQL数据库.问题是该程序(使用Xcode编译)总是崩溃
EXC_BAD_ACCESS (code=13, address=0x0)
Run Code Online (Sandbox Code Playgroud)
在打电话时
driver->connect(url, user, pass)
Run Code Online (Sandbox Code Playgroud)
在Xcode中我创建了一个完整的新项目(OS X>命令行工具),在main.cpp中插入代码(见下文),添加了Boost和MySQL Connector头包含路径以及libmysqlcppconn.6.1.1.1.dylib作为Link库并点击"运行"按钮.
接下来的事情是,当我手动编译程序时
c++ -o test -I /usr/local/mysqlConnector/include/ -lmysqlcppconn main.cpp
Run Code Online (Sandbox Code Playgroud)
程序运行正常,并在表上运行INSERT语句.
程序代码取自MySQL Connector/C++示例,即pthreads.cpp示例,但截断为基本部分:
/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <mysql_connection.h>
#include <mysql_driver.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
std::string url;
std::string user;
std::string pass;
std::string database;
/**
* Usage example for Driver, Connection, (simple) Statement, ResultSet
*/
int main(int argc, const char **argv)
{
sql::Driver *driver;
std::auto_ptr< sql::Connection > con; …Run Code Online (Sandbox Code Playgroud) 我在委托方法中创建了一个块,我用它来调用另一个类中的静态方法.即使我启用了NSZombies,我也会收到EXC_BAD_ACCESS错误.这里有一些关于类似问题的帖子 - 我认为这个是最接近的:
ARC:从委托方法中使用的内部块获取EXC_BAD_ACCESS
但是,到目前为止,我还没有找到任何有帮助的东西.这是代码:
@interface MyClass()
@property (nonatomic, copy) CaseBlock c;
@end
....
//NSURLConnection delegate method
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSDictionary *d = [NSDictionary dictionaryWithObjectsAndKeys:
//blows up after executing this
^() { [AnotherClass staticMethod]; },authURL,
^() { NSLog(@"TODO");}, searchURL,
^() { NSLog(@"TODO"); }, itemURL,
nil];
self.c = [[d objectForKey:[self.url path]] copy];
if (self.c) {
self.c();
} else { NSLog(@"WARN unexpected response path"); }
}
Run Code Online (Sandbox Code Playgroud)
这是我第一次尝试使用块,但我可以说这导致了问题,因为从块外部调用方法可以正常工作.而且,据我所知,我编写的所有代码实际上都被执行了,然后发生了EXC_BAD_ACCESS错误.但是,我是Objective-C的新手,所以如果我错了,请纠正我.
NSInteger total = 4556; // Initialize total
// NSLog all fields to make sure the variables are in place
NSLog(@"%@", originField.text);
NSLog(@"%@", destinationField.text);
NSLog(@"%i", [startField.text integerValue]);
NSLog(@"%i", [endField.text integerValue]);
NSLog(@"%i", total);
// Create a dictionary of them
NSDictionary *newDict = [[NSDictionary alloc] initWithObjectsAndKeys:@"Sat. Jan 6th, 2014", @"date", originField.text, @"origin", destinationField.text, @"destination", [startField.text integerValue], @"start", [endField.text integerValue], @"end", total, @"total", @"Personal", @"type", nil];
// EXC_BAD_ACCESS CODE 1
Run Code Online (Sandbox Code Playgroud)
我尝试在Instruments中使用Zombies模板,但我从未得到过对话框.在破坏点时,应用程序在initWithObjectsAndKeys上崩溃.我的死变量在哪里?