我在iPhone编程中的UITextView中显示数据时遇到了困难.
我正在分析传入的音频数据(来自麦克风).为了做到这一点,我从SignalAnalyzer类创建了一个对象"analyzer",它执行传入数据的分析.我想要做的是实时显示TextView中的每个新传入数据.
因此,当我按下按钮时,我创建了分析传入数据的对象"分析器".每次有新数据时,我都需要在TextView中将它显示在屏幕上.
我的问题是我收到错误,因为(我认为)我正在尝试向父类发送消息(在我的UITextView中显示内容的那个:它有一个在Interface Builder中链接的UITexView实例变量) .我该怎么做才能告诉我的父班需要显示什么?或者我应该如何设计我的课程以自动显示?
谢谢您的帮助.
PS:这是我的错误:
2010-04-19 14:59:39.360 MyApp[1421:5003] void WebThreadLockFromAnyThread(),
0x14a890: Obtaining the web lock from a thread other than the main thread
or the web thread. UIKit should not be called from a secondary thread.
2010-04-19 14:59:39.369 MyApp[1421:5003] bool _WebTryThreadLock(bool),
0x14a890: Tried to obtain the web lock from a thread other than the main thread
or the web thread. This may be a result of calling to UIKit from a secondary thread.
Crashing now...
Program received …Run Code Online (Sandbox Code Playgroud) 这真的在扭曲我的想法...我正在尝试访问我在viewDidLoad中定义的IBAction中的NSMutableArray.不幸的是,我一直在获得EXC_BAD_ACCESS.
我对这一切都很陌生,所以我真的很感激我对自己做错了什么.
下面找到相应的代码摘录.
CounterViewController.h:
@interface CounterViewController : UIViewController{
NSMutableArray *countHistoryArray;
}
@property(nonatomic, retain) NSMutableArray *countHistoryArray;
Run Code Online (Sandbox Code Playgroud)
CounterViewController.m:
@implementation CounterViewController
@synthesize countHistoryArray;
- (void)viewDidLoad {
[super viewDidLoad];
//Fill array with some dummy data
self.countHistoryArray = [[NSMutableArray alloc] init];
NSDate *now = [[[NSDate alloc] init] autorelease];
CurrentCount *historicCount = [[[CurrentCount alloc]
initWithCount:[NSNumber numberWithInteger:22]
description:@"Testcount"
dateAndTime:now] autorelease];
[self.countHistoryArray addObject: historicCount];
//Do some logging - everything is working fine here!
NSLog(@"%@", [self.countHistoryArray description]);
}
//Later on we click on a button and want to use …Run Code Online (Sandbox Code Playgroud) 我已经在这个工作了很长一段时间但似乎无法解决它.我有一个核心数据应用程序,也支持文档共享,因此我正在尝试在库文件夹中为sqlite db创建一个目录.
- (NSURL *)applicationPrivateDocumentsDirectory {
NSString *libraryDirectory = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
NSString *privateDocs = [libraryDirectory stringByAppendingPathComponent:@"PrivateDocuments"];
NSFileManager *fileMgr = [[NSFileManager alloc] init];
if (![fileMgr fileExistsAtPath:privateDocs]) {
NSLog(@"Does not exist");
NSError *error;
[fileMgr createDirectoryAtPath:privateDocs withIntermediateDirectories:YES attributes:nil error:&error];
NSLog(@"%@", [error description]);
}
NSURL *retURL = [NSURL fileURLWithPath:privateDocs];
return retURL;
}
Run Code Online (Sandbox Code Playgroud)
调试控制台输出"不存在",然后是"EXC_BAD_ACCESS"
.非常感谢任何帮助.
这是代码:
#include <stdio.h>
Run Code Online (Sandbox Code Playgroud)
int main(int argc,const char*argv []){int num; 结构接触;
struct contact {
double foneNumber;
char firstName;
char lastName;
};
typedef struct contact cntct;
cntct bob;
bob.foneNumber = 15555555555;
bob.firstName = "bob";
bob.lastName = "builder";
cntct fudge;
fudge.foneNumber = 15444444444;
fudge.firstName = "fudge";
fudge.lastName = "cornelius";
cntct Siddhartha;
Siddhartha.foneNumber = 15333333333;
Siddhartha.firstName = "Siddhartha";
Siddhartha.lastName = "Gautama";
while (1) {
printf("Would you like to see contact 1, 2, or 3 (0 to quit)?");
scanf("%d", &num);
switch (num)
{
case 1: …Run Code Online (Sandbox Code Playgroud) 根据Xcode中的堆栈跟踪,我的程序在这里断开并给出了EXC_BAD_ACCESS:
int main (int argc, const char * argv[]) {
float usd,btc,bid,ask,order_price,possible_price;
DateData * prices = load_prices(); <---
DateData * load_prices(){
FILE * file = fopen("price.dat", "rb"); <---
Run Code Online (Sandbox Code Playgroud)
我确定这与该行代码无关,而是后来的代码.在直到稍后才调用的函数中,有一行代码似乎破坏了程序.当它从执行行之前的函数返回时,程序没有这个问题,但如果它应该从行后的函数返回,则存在这个问题.
代码行是对OpenCL的调用.它是否以某种方式破坏了该计划?
err = clEnqueueReadBuffer(ocl_data->commands, ocl_data->output, CL_TRUE, 0, sizeof(CombinationResult) * PPO_COMBINATIONS, (*PPO_results)[x] + PPO_COMBINATIONS*(p + 5), 0, NULL, NULL);
Run Code Online (Sandbox Code Playgroud)
PPO_COMBINATIONS定义为整数宏,PPO_results的类型为CombinationResult(*)[3] [PPO_COMBINATIONS*11].ocl_data-> commands的类型为cl_command_queue,ocl_data-> output的类型为cl_mem.错误,p和x的类型为int.
我正在使用Xcode和"Apple LLVM Compiler 3.0"."LLVM GCC 4.2"编译器出于某种原因给出了"架构i386的格式错误的元数据记录".
这是使用命令行编译和运行gdb时的结果:
Matthew-Mitchell:Parrallel BitCoin Trading Algorithm matt$ gcc -g cmain.c -o test -lcurl -framework OpenCL -std=c99 -arch i386
Matthew-Mitchell:Parrallel BitCoin Trading Algorithm matt$ gdb …Run Code Online (Sandbox Code Playgroud) 当我insertSubview:atIndex:在iPhone上使用该方法时,程序无法运行,并在main.m文件中使用EXC_BAD_ACCESS.但是,当我使用presentModalViewController该程序运行完美.
此外,方法switchToView在第一次使用时工作,具有不同的往返,但第二次没有.
出了什么问题?
这是我的代码:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ShowBookDetails *sbd = [[ShowBookDetails alloc] initWithNibName:@"ShowBookDetails" bundle:nil];
[self switchToView:sbd from:self];
}
Run Code Online (Sandbox Code Playgroud)
我的方法看起来像:
-(void)switchToView:(UIViewController*)nextView from:(UIViewController*)currentView
{
[currentView.view insertSubview:nextView.view atIndex:1];
}
Run Code Online (Sandbox Code Playgroud) 我通常不会问这样的问题,但我真的无法理解它.我有一个类'GetTableInfoFromDatabase',它连接到我的数据库并下载一些JSON.这在我的标签栏应用程序的第一个屏幕上运行得很好.我可以调用getNewData方法,因为我想要有效地刷新数据.
当我尝试创建'GetTableInfoFromDatabase'类的实例并从另一个选项卡调用相同的方法时,我的问题出现了.我收到以下错误:
*** -[GetTableInfoFromDatabase respondsToSelector:]: message sent to deallocated instance 0x1d89e830
Run Code Online (Sandbox Code Playgroud)
有趣的是,我正在使用ARC.罪魁祸首(在我看来)是ASIHTTPRequest.我必须启用-fno-objc-arc才能使项目进行编译.此库用于GetTableInfoFromDatabase类.
这是班级:
- (void) getEventDataWithSender:(id)sender{
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"-------.com/getdata.php"]];
[request setDelegate:self];
NSLog(@"Running!");
[request startAsynchronous];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
self.managedObjectContext = appDelegate.managedObjectContext;
}
Run Code Online (Sandbox Code Playgroud)
这就是我所说的:
GetTableInfoFromDatabase *getInfo = [[GetTableInfoFromDatabase alloc]init];
[getInfo getEventDataWithSender:self];
Run Code Online (Sandbox Code Playgroud)
我甚至改变了标签的顺序,所以第一个要显示的标签只是调用这个方法,没有别的.甚至在'GetTableInfoFromDatabase'之前已经由最后一次初始化它的类初始化之前.仍然崩溃.
有没有人有任何想法?这太令人沮丧了!
我原以为'self.data ='会保留autorelease NSMutableArray对象和它包含的NSMutableDictionary对象,但最终我在表的cellForRowAtIndexPath方法尝试访问self.data中的NSDictionaries时得到EXC_BAD_ACCESS.
@property (strong, nonatomic) NSMutableArray *data;
- (void) updateReceivedData:(NSData *) jsonData
{
NSMutableArray *fetchedData = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
self.data = [self convertDates:fetchedData withFormat:kMySQLDateTimeFormat];
[self.tableView reloadData];
}
}
- (NSMutableArray*) convertDates:(NSMutableArray *) array withFormat:(NSString *) format
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:format];
NSMutableArray *newArray = [NSMutableArray arrayWithArray:array];
for (NSMutableDictionary *dict in newArray)
{
for (id key in dict.allKeys)
{
if ([[dict objectForKey:key] isKindOfClass:[NSString class]])
{
NSString *value = [dict objectForKey:key];
NSDate *date = [dateFormatter dateFromString:value]; …Run Code Online (Sandbox Code Playgroud) 我一直在讨论这个问题,因为我不认为我完全理解保留周期.我对此完全陌生,我正在努力了解更多相关信息.
我收到带有以下代码的EXC_BAD_ACCESS消息.
我开始使用weakSelf,因为如果我只使用self.successBLock();我会收到关于保留周期的2个警告.确切的警告是:
Capturing 'self' strongly in this block is likely to lead to a retain cycle
Run Code Online (Sandbox Code Playgroud)
也许我甚至不打算使用弱者,但我对此不太确定.
这是我在块中使用weakSelf的部分:
__weak Request *weakSelf = self;
[_operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
weakSelf.successBlock(operation.response, responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
weakSelf.failureBlock(operation.response, error);
}];
Run Code Online (Sandbox Code Playgroud)
这是我分配块属性的方式:
typedef void (^successBlock)(NSHTTPURLResponse *response, id responseObject);
typedef void (^failureBlock)(NSHTTPURLResponse *response, NSError *error);
@property (nonatomic, copy) successBlock successBlock;
@property (nonatomic, copy) failureBlock failureBlock;
Run Code Online (Sandbox Code Playgroud) exc-bad-access weak-references objective-c objective-c-blocks retain-cycle
我在做HMAC-SHA256编码.试过但没有找到任何解决方案.
#include <CommonCrypto/CommonHMAC.h>
- (NSString *)hmacWithKey:(NSString *)key andData:(NSString *)data
{
const char *cKey = [key cStringUsingEncoding:NSASCIIStringEncoding];
const char *cData = [data cStringUsingEncoding:NSASCIIStringEncoding];
unsigned char cHMAC[CC_SHA256_DIGEST_LENGTH];
///////////////////////////////////////////////////////////////
////but on below line of code i am getting EXC_BAD_ACCESS//////
///////////////////////////////////////////////////////////////
CCHmac(kCCHmacAlgSHA256, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
//////////////////////////////////////////////
NSData *out = [NSData dataWithBytes:cHMAC length:CC_SHA256_DIGEST_LENGTH];
// description converts to hex but puts <> around it and spaces every 4 bytes
NSString *hash = [out description];
hash = [hash stringByReplacingOccurrencesOfString:@" " withString:@""];
hash = [hash stringByReplacingOccurrencesOfString:@"<" …Run Code Online (Sandbox Code Playgroud) exc-bad-access ×10
iphone ×5
objective-c ×5
xcode ×3
c ×2
ios ×2
debugging ×1
directory ×1
encoding ×1
hmac ×1
llvm ×1
opencl ×1
properties ×1
retain ×1
retain-cycle ×1
struct ×1
typedef ×1
uitextview ×1