我一直在靠墙撞墙几天,需要一些帮助.我觉得我在做一些非常愚蠢的事情,但我找不到问题.这是表视图的控制器.我把SQL放在一行以简化它,作为此错误的故障排除的一部分.通常,它将位于模型类中的存取方法中.
它通过SQL读取就好了.找到这两个对象,将它们加载到todaysWorkout数组中,然后为表视图构建单元格.表视图实际上出现在scree上,然后抛出EXC_BAD_ACCESS.
我运行了仪器,它显示以下内容:
0 CFString Malloc 1 00:03.765 0x3946470 176基础 - [NSPlaceholderString initWithFormat:locale:arguments:]
1 CFString Autorelease 00:03.765 0x3946470 0 Foundation NSRecordAllocationEvent
2 CFString CFRelease 0 00:03.767 0x3946470 0带它 - [WorkoutViewController viewDidLoad]
3 CFString Zombie -1 00:03.917 0x3946470 0基础NSPopAutoreleasePool
这是控制器的源代码.我把它全部放在那里以防万一有什么东西导致问题.我真诚地感谢我能得到的任何帮助:
标头:
#import <UIKit/UIKit.h>
#import <sqlite3.h>
#import "NoteCell.h"
#import "BIUtility.h"
#import "Bring_ItAppDelegate.h"
#import "MoveListViewController.h"
@class MoveListViewController;
@class BIUtility;
@interface WorkoutViewController : UITableViewController {
NSMutableArray *todaysWorkouts;
IBOutlet NoteCell *woNoteCell;
MoveListViewController *childController;
NSInteger scheduleDay;
BIUtility *bi;
}
@property (nonatomic, retain) NSMutableArray *todaysWorkouts;
@property (nonatomic, …Run Code Online (Sandbox Code Playgroud) 我有一个NSNumber通过第三方API传递,当我在索引上调用intValue时,我得到一个EXC_BAD_ACCESS错误:
-(CPFill *) barFillForBarPlot:(CPBarPlot *)barPlot recordIndex:(NSNumber *)index;
{
NSLog(@"bar index %i", index);
int value = [index intValue];
}
Run Code Online (Sandbox Code Playgroud)
我在调试器中得到的输出是:
条形指数0
条形指数1
程序接收信号:"EXC_BAD_ACCESS".
到底他妈发生了什么?
我注意到第一次调用该方法时,index是nil,但下次显然不是......
我怎么调试这个?!?!它是如此微不足道的事情,但我似乎无法解决它!
嗨,我有以下c ++程序:
#include <iostream>
#include <fstream>
#include <vector>
#include <sstream>
#include <boost/foreach.hpp>
#include <stdexcept>
#include <boost/flyweight.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
struct entry
{
int file;
std::vector<double> a;
};
void my_file(const std::string&file, std::vector<entry> &data, int i){
try{
std::ifstream in(file.c_str());
entry e;
std::string line;
e.file = i;
while(getline(in,line)){
try{
data[i].a.push_back( boost::lexical_cast<double> (line));
}catch(boost::bad_lexical_cast bad){
//std::cerr << bad.what() << std::endl;
}
}
}catch(std::runtime_error err){
std::cerr << err.what() << std::endl;
}
}
void write_file(const std::string &file,std::vector<entry> data,const char* t_path){
try{ …Run Code Online (Sandbox Code Playgroud) 我UITableViewController didSelectRowAtIndexPath通过以下方式覆盖了我的方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
PhotoListViewController *photosViewController = [[PhotoListViewController alloc] initWithStyle:UITableViewStylePlain];
NSLog(@"Let's see what we got %d", [[fetchedResultsController fetchedObjects] count]);
Person *person = [fetchedResultsController objectAtIndexPath:indexPath];
photosViewController.person = person;
photosViewController.title = [person.name stringByAppendingString:@"'s Photos"];
[self.navigationController pushViewController:photosViewController animated:YES];
[photosViewController release];
}
Run Code Online (Sandbox Code Playgroud)
每当我试图访问fetchedResultsController我得到崩溃时,我在这里设置它:
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"person = %@", person];
fetchedResultsController = [[FlickrFetcher sharedInstance] fetchedResultsControllerForEntity:@"Photo" withPredicate:predicate];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
我只用我的dealloc方法发布它
exc-bad-access objective-c uitableview didselectrowatindexpath ios
#include <stdio.h>
int main (int argc, const char * argv[])
{
FILE *fp;
fp=fopen("/Users/--------/Desktop/C.txt", "w");
putc("C", "/Users/-------/Desktop/C.txt");
fclose(fp);
}
Run Code Online (Sandbox Code Playgroud)
这是我将字母"C"写入文本文件C.txt的简单代码.每次写入时都会收到错误代码EXC_BAD_ACCESS.什么事情发生了?
当我使用这段代码时:
NSLog(@"- (void)connectionDidFinishLoading:(NSURLConnection *)%@", connection);
[connection release];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
[responseData release];
NSDictionary *missionsDict = [responseString JSONValue];
/*NSArray *luckyNumbers = [json objectWithString:responseString error:&error];*/
NSLog(@"user Info array is: %@", missionsDict);
// NSDictionary *array = [luckyNumbers1 objectForKey:@"data"];
NSDictionary *missionsData;
missionsData = [missionsDict objectForKey:@"data"];
NSLog(@"missionsData is: %@", missionsData);
NSEnumerator *inner = [missionsData objectEnumerator];
UIScrollView *missionsScroll;
missionsScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
missionsScroll.contentSize = CGSizeMake(320, 1005);
[self.view addSubview:missionsScroll];
id value;
int badgeY1;
int badgeY2;
int badgeY3;
badgeY1 = …Run Code Online (Sandbox Code Playgroud) 我在代码的这一部分有一些随机崩溃:
-(void) goBack {
[self performSelectorInBackground:@selector(addActivityIndicator) withObject:nil];
[self.navigationController popViewControllerAnimated:YES];
}
- (void)addActivityIndicator {
@autoreleasepool {
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
UIBarButtonItem * barButton = [[UIBarButtonItem alloc] initWithCustomView:activityView];
[activityView startAnimating];
self.navigationItem.leftBarButtonItem = barButton;
}
}
Run Code Online (Sandbox Code Playgroud)
当我想退出存在这些方法的屏幕时,另一个ViewController必须处理一些数据.为了通知用户正在进行处理,我在导航栏的左侧按钮中添加了一个活动指示器.
问题是有时候我会得到一个exc_bad_accessin addActivityIndicator方法.频率非常随机,有时XCode @autoreleasepool会在结束时显示错误,有时候会显示错误self.navigationItem.leftBarButtonItem = barButton;
我想有时我的viewController被销毁但是线程仍在运行并尝试访问不再存在的对象的navigationItem.但我不确定这是不是问题,我不知道如何解决它.
我在我的项目中使用ARC,这个问题出现在我测试的所有iOS版本中.
拜托,任何人都可以向我解释发生了什么,我该如何解决这个问题?
谢谢.
我很难过.我正在粘贴下面的程序.
void printGrid(int n,char grid[n][n]){
for(int i = 0; i<n ; i ++) {
printf("\n%s",grid[i]);
}
}
int main() {
char grid[6][6]= {"-----","-----","-----","-----","-----"};
printGrid(5, grid);
for(int i = 0; i<5 ; i ++) {
printf("\n%s",grid[i]);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
-----
-
--
---
-----
-----
-----
-----
-----
Run Code Online (Sandbox Code Playgroud)
为什么同一个for循环在函数外部和内部产生不同的输出printGrid?
所以我有一个Task实体类(Core Data),我试图覆盖其中一个字符串(timeIntervalString)的setter,因此它可以显示在表视图单元格的详细文本标签中.出于某种原因,我得到一个像这样的EXC_BAD_ACCESS错误:

[Tasks timeIntervalString]一直持续到37355 ...
这是我的代码:
-(NSString *)timeIntervalString{
NSUInteger seconds = (NSUInteger)round(self.timeInterval);
if ((seconds/3600) == 0){
if (((seconds/60) % 60) == 1) {
self.timeIntervalString = [NSString stringWithFormat:@"%u MIN", ((seconds/60) % 60)];
} else {
self.timeIntervalString = [NSString stringWithFormat:@"%u MINS", ((seconds/60) % 60)];
}
} else if ([self.conversionInfo hour] == 1) {
if (((seconds/60) % 60) == 0){
self.timeIntervalString = [NSString stringWithFormat:@"%u HR", (seconds/3600)];
} else if (((seconds/60) % 60) == 1) {
self.timeIntervalString = [NSString stringWithFormat:@"%u HR %u MIN", (seconds/3600), …Run Code Online (Sandbox Code Playgroud) 我正在尝试调试与NSArray相关的问题.我得到一个例外:
EXC_BAD_ACCESS(代码= EXC_1386_GPFLT)在此行:
NSArray *items = [[NSArray alloc] initWithObjects:@"A", "B", "C", nil];
Run Code Online (Sandbox Code Playgroud)
这段代码在NSView内部 - (id)initWithFrame:(NSRect)框架内.
是什么导致我得到这个例外?我是Google-d的例外,我还没有找到其他人获得它.
此项目适用于OS X而非iOS.
exc-bad-access ×10
objective-c ×6
ios ×4
iphone ×3
c ×2
arrays ×1
c++ ×1
cocoa ×1
int ×1
macos ×1
memory ×1
nslog ×1
nsnumber ×1
nsstring ×1
nsthread ×1
printf ×1
text-files ×1
uitableview ×1
vector ×1