我很困惑为什么我的应用程序崩溃了这个错误.
我已经实现了displayLayer方法(用于渲染CALayer).这个方法第一次运行时工作正常.但随后的调用是在发生错误时.
当self.bgColor被设置为上下文填充颜色时,似乎会发生错误.有趣的...如果我在那条线之前创建了bgColor,那么事情就会奏效.但就目前而言,bgColor是在初始化此类(displayLayer方法的容器)时创建的.
-(void)displayLayer:(CALayer *)caLayer
{
UIGraphicsBeginImageContext(caLayer.frame.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, self.bgColor);
CGContextFillRect(context, CGRectMake(0, 0, 320, 25));
[self drawText:context];
// get image buffer
UIImage *imageBuffer = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// set layer contents to image buffer
caLayer.contents = (id)[imageBuffer CGImage];
}
Run Code Online (Sandbox Code Playgroud) 我确定这是非常简单的我缺少的东西.我用makeKeyAndOrderFront:它打开一个窗口,它第一次工作.当我关闭窗口并尝试再次打开它时,它会退出并给我错误EXC_BAD_ACCESS.我的代码是这样的:
- (IBAction)viewScreen:(id)sender {
[screenView makeKeyAndOrderFront:sender];
}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚为什么会发生这种情况并且调试器控制台没有说什么.
提前致谢
我在我的一个对象上声明了一个基元数组,似乎无法从外部访问它.我在ObjectiveC上相当新,是否有一些明显的错误?
头文件:
@interface MyObject : NSObject {
//@public <-- this shouldn't be necessary, right? I have accessors!
float *d;
}
@property float *d;
Run Code Online (Sandbox Code Playgroud)
.m文件:
@synthesize d;
-(id) init {
...
self.d = (float*) malloc(sizeof(float) * n); //n > 1000
...
}
Run Code Online (Sandbox Code Playgroud)
执行访问的位置:
MyObject* k = [MyObject init];
NSLog(@"%f",k.d[0]);
Run Code Online (Sandbox Code Playgroud)
我在最后一行收到一个EXC_BAD_ACCESS错误,但我似乎无法找到原因.有人看到我失踪的东西吗?
我的应用程序工作正常,几分钟后,在编辑应用程序的另一部分后,它开始从我甚至没有工作的视图控制器抛出EXC_BAD_ACCESS错误.我之间唯一可以认为可能影响它的是,我编辑 - > Refractor->转换为Obj-C ARC ...我只是为指定的文件做了它,而不是我的整个项目是混乱.当我相信错误开始发生时,我正在关注本教程... http://sonnyparlin.com/2011/12/pulltorefresh-ios-5-and-arc-tutorial/ 此外,应用程序启动正常,它只是在崩溃时崩溃在tableview中单击一个单元格.任何帮助将不胜感激!
此行发生错误:
self.releaselink = [[sortedArray objectAtIndex:indexPath.row] objectForKey:@"link"];
Run Code Online (Sandbox Code Playgroud)
这是我的代码,其中错误源自:
@implementation PressReleaseViewController
@synthesize releaselink;
UILabel *departmentNamesLabel;
CGRect *departmentNamesFrame;
- (void)viewDidLoad {
// Load path to plist and sort based on "name"
NSString *path = [[NSBundle mainBundle] pathForResource:
@"departments" ofType:@"plist"];
array = [[NSMutableArray alloc] initWithContentsOfFile:path];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
sortedArray = [array sortedArrayUsingDescriptors:[NSArray arrayWithObject:descriptor]];
}
// How many sections are in the table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// Set how …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用CAlayers进行逐帧动画.我正在使用本教程http://mysterycoconut.com/blog/2011/01/cag1/进行此操作,但一切都适用于禁用ARC,当我尝试用ARC重写代码时,它可以在模拟器上完美地工作但在设备上我的访问内存不好.
Layer Class接口
#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
@interface MCSpriteLayer : CALayer {
unsigned int sampleIndex;
}
// SampleIndex needs to be > 0
@property (readwrite, nonatomic) unsigned int sampleIndex;
// For use with sample rects set by the delegate
+ (id)layerWithImage:(CGImageRef)img;
- (id)initWithImage:(CGImageRef)img;
// If all samples are the same size
+ (id)layerWithImage:(CGImageRef)img sampleSize:(CGSize)size;
- (id)initWithImage:(CGImageRef)img sampleSize:(CGSize)size;
// Use this method instead of sprite.sampleIndex to obtain the index currently displayed on screen
- (unsigned int)currentSampleIndex;
@end
Run Code Online (Sandbox Code Playgroud)
图层类实现
@implementation …Run Code Online (Sandbox Code Playgroud) xcode core-animation exc-bad-access objective-c automatic-ref-counting
我开始iOS开发,我有这个代码:
首先我声明listOfItems NSMutableArray:
@interface SAMasterViewController () {
NSMutableArray *listOfItems;
}
@end
Run Code Online (Sandbox Code Playgroud)
现在,这是代码的一部分,它给了我一个"EXC_BAD_ACCESS(代码= 1,地址= 0x5fc260000)"错误.错误在"individual_data"对象的最后一行中给出.
listOfItems = [[NSMutableArray alloc] init];
for(NSDictionary *tweetDict in statuses) {
NSString *text = [tweetDict objectForKey:@"text"];
NSString *screenName = [[tweetDict objectForKey:@"user"] objectForKey:@"screen_name"];
NSString *img_url = [[tweetDict objectForKey:@"user"] objectForKey:@"profile_image_url"];
NSInteger unique_id = [[tweetDict objectForKey:@"id"] intValue];
NSInteger user_id = [[[tweetDict objectForKey:@"user"] objectForKey:@"id"] intValue ];
NSMutableDictionary *individual_data = [NSMutableDictionary dictionaryWithObjectsAndKeys:
text, @"text_tweet",
screenName,@"user_name",
img_url, @"img_url",
unique_id, @"unique_id",
user_id, @"user_id", nil];
[listOfItems addObject:individual_data];
}
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我正在尝试使用3个元素创建一个字典对象,其中一个元素是BOOL值.我收到一个EXC_BAD_ACCESS(代码= EXC_ARM_DA_ALIGN,地址= 0x5),我使用[NSDictionary dictionaryWithObjectsAndKeys:object,key,nil]将BOOL存储为对象
以下代码有什么问题:
- (void) retrieveAchievmentMetadata
{
[GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:
^(NSArray *descriptions, NSError *error) {
if (error != nil)
{
// Process the error.
}
if (descriptions != nil)
{
[self setAchievementDescriptions:[[NSMutableDictionary alloc] init]];
for (GKAchievementDescription *achievementDescription in descriptions) {
NSDictionary *achievementData = [NSDictionary dictionaryWithObjectsAndKeys:
[achievementDescription achievedDescription], @"Achieved Description",
[achievementDescription maximumPoints], @"Maximum Points",
[NSNumber numberWithBool:FALSE], @"Level Is Completed", nil];
[achievementDescriptions setObject:achievementData forKey:[achievementDescription identifier]];
}
}
}];
Run Code Online (Sandbox Code Playgroud)
}
行上发生EXC_BAD_ACCESS错误
[NSNumber numberWithBool:FALSE], @"Level Is Completed", nil];
Run Code Online (Sandbox Code Playgroud) memory-management exc-bad-access objective-c nsdictionary ios
我正在为NSDate编写一个扩展,它提供了一些可用的初始化程序.这里的最终目标是从API获取日期时间字符串并将其解析为NSDate,例如
let createdAt = NSDate(apiDateTimeString: "2016-03-29T18:33:49+06:00")
let createdAt = NSDate(apiDateTimeString: "2016-03-29T18:33:49.730+06:00")
Run Code Online (Sandbox Code Playgroud)
日期时间字符串可以采用以下两种格式之一:
yyyy-MM-dd'T'HH:mm:ssZZZZZyyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ这是扩展的样子:
import Foundation
public extension NSDate {
// MARK: Custom Initializers
public convenience init(date: NSDate) {
self.init(timeInterval: 0.0, sinceDate: date)
}
public convenience init?(dateString: String, formatString: String) {
let formatter = NSDateFormatter()
formatter.dateFormat = formatString
formatter.locale = NSLocale(localeIdentifier: "en_US_POSIX")
if let date = formatter.dateFromString(dateString) {
self.init(date: date)
} else {
return nil
}
}
public convenience init?(apiDateTimeString: String?) {
guard let dateString = apiDateTimeString else { …Run Code Online (Sandbox Code Playgroud) 我们最近修改了我们的线程机制,支持dispatch_async在大多数地方使用'(在做了很多关于NSOperation和dispatch_async的阅读之后)*.然后我们的代码开始在代码的各个部分与EXC_BAD_ACCESS崩溃,总是在dispatch_async(queue,...)部分,没有明确的模式.通常在20分钟后发生--2小时.
我们的dispatch_async块用于通知听众,如下所示:
NSMutableSet *_listeners; // Initialised elsewhere and filled with interested listeners
void(^block)(id listener); // Block to execute
@synchronized(_listeners) {
for (id listener in _listeners) {
dispatch_async_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); // We used different queues for different listeners, but showing only one type of queue here for brevity
dispatch_async(queue, ^{ // CRASHING LINE
block(listener);
});
}
}Run Code Online (Sandbox Code Playgroud)
常见的症状是:
(这是一个自我回答的问题)
*我们喜欢简单dispatch_async,不需要阻止/依赖功能,NSOperationQueue我们很快就会转向C++,所以想保持低水平.
exc-bad-access dispatch grand-central-dispatch ios dispatch-async
我对编码很新,我决定开始快速学习.我明显遇到了一个bug问题而且我的应用程序运行不正常.我已将所有代码附加到我的项目中.希望有人可以提供帮助 提前致谢
exc-bad-access ×10
ios ×6
objective-c ×4
iphone ×3
arrays ×1
cocoa ×1
dispatch ×1
foundation ×1
nsdate ×1
nsdictionary ×1
sender ×1
swift ×1
swift2 ×1
xcode ×1