i'm really new to Objective-C and so i got until now, trying to make a little FileDialog which starts after selecting some Files a new Thread, searching for words in the files and returning them to screen. But right now i'm stuck at the point where the thread says EXC_BAD_ACCESS when trying to get the count of items in the array. My code right now:
.h
@interface DoSthThread : NSObject {
@private
NSArray *fileArray;
NSProgressIndicator *pbar;
BOOL keepRunning;
}
@property(readwrite) NSArray *fileArray;
@property(readwrite) NSProgressIndicator *pbar;
@property(readwrite) BOOL keepRunning;
- (void)doSth;
@end
@interface FileSelector : NSObject {
@private
NSArray *fileArray;
IBOutlet NSButton *selectBtn,*doSthBtn;
IBOutlet NSProgressIndicator *pbar;
DoSthThread *newThread;
}
- (IBAction)openFileDialog:(id)sender;
- (IBAction)doSthBtnClicked:(id)sender;
@end
.m
@implementation FileSelector
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
newThread = [[doSthThread alloc] init];
[newThread setPbar:pbar];
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
- (IBAction)openFileDialog:(id)sender {
int i; // Loop counter.
// Create the File Open Dialog class.
NSOpenPanel* openDlg = [NSOpenPanel openPanel];
// Enable the selection of files in the dialog.
[openDlg setCanChooseFiles:YES];
[openDlg setAllowsMultipleSelection:YES];
// Display the dialog. If the OK button was pressed,
// process the files.
if ( [openDlg runModalForDirectory:nil file:nil] == NSOKButton )
{
// Get an array containing the full filenames of all
// files and directories selected.
NSArray* files = [openDlg filenames];
fileArray = [files sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
// Loop through all the files and process them.
if([fileArray count] > 0) {
[doSthBtn setEnabled:YES];
[newThread setFileArray:files];
}
}
}
- (IBAction)doSthBtnClicked:(id)sender {
[NSThread detachNewThreadSelector:@selector(doSth) toTarget:newThread withObject:nil];
}
@end
@implementation DoSthThread
@synthesize fileArray, pbar, keepRunning;
- (void)doSth {
for( int i = 0; i < [fileArray count]; i++ )
{
//Do sth ;)/>
}
}
@end

New Topic/Question
Reply



MultiQuote




|