I have 4 tabs in UITabBarcontroller. My problem is i need to navigate to next tab by user click while first tab process in on going?? how to run the process on background??
Now second tab not working while the first tab view in process. I used PerformSelectorInBackground but it's not help me?? Can any one help me Please????
Am poor in english, can you understand my problem?
Yuva.M
Run your heavy process with NSThread.
Snippet from here:
- (IBAction) startThreadButtonPressed:(UIButton *)sender {
[NSThread detachNewThreadSelector:#selector(startTheBackgroundJob) toTarget:self withObject:nil];
}
- (void)startTheBackgroundJob {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// wait for 3 seconds before starting the thread, you don't have to do that. This is just an example how to stop the NSThread for some time
[NSThread sleepForTimeInterval:3];
[self performSelectorOnMainThread:#selector(makeMyProgressBarMoving) withObject:nil waitUntilDone:NO];
[pool release];
}
- (void)makeMyProgressBarMoving {
float actual = [threadProgressView progress];
if (actual < 1) {
threadProgressView.progress = actual + 0.01;
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(makeMyProgressBarMoving) userInfo:nil repeats:NO];
}
}
Related
The accessibility inspector is turned on by my KIF tests (apparently it's necessary for KIF to work.) Problem is, its window occludes controls some subsequent UI tests need to tap on and those tests fail.
How can I turn the Accessibility Inspector off when my KIF tests are done with it so my UI Tests can run?
(Turning it off "manually" from the simulator's Settings app is not a solution—I'm looking for something I can call from code, set in the target or...?)
It is not on by default. You must turn it on manually.
I saw the following on Stew Gleadow's blog.
You just need to change the line:
CFPreferencesSetValue(CFSTR("ApplicationAccessibilityEnabled"), kCFBooleanFalse, accessibilityDomain, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
change kCFBooleanTrue to kCFBooleanFalse.
+ (void)_enableAccessibilityInSimulator {
NSAutoreleasePool *autoreleasePool = [[NSAutoreleasePool alloc] init];
NSString *appSupportLocation = #"/System/Library/PrivateFrameworks/AppSupport.framework/AppSupport";
NSDictionary *environment = [[NSProcessInfo processInfo] environment];
NSString *simulatorRoot = [environment objectForKey:#"IPHONE_SIMULATOR_ROOT"];
if (simulatorRoot) {
appSupportLocation = [simulatorRoot stringByAppendingString:appSupportLocation];
}
void *appSupportLibrary = dlopen([appSupportLocation fileSystemRepresentation], RTLD_LAZY);
CFStringRef (*copySharedResourcesPreferencesDomainForDomain)(CFStringRef domain) = dlsym(appSupportLibrary, "CPCopySharedResourcesPreferencesDomainForDomain");
if (copySharedResourcesPreferencesDomainForDomain) {
CFStringRef accessibilityDomain = copySharedResourcesPreferencesDomainForDomain(CFSTR("com.apple.Accessibility"));
if (accessibilityDomain) {
CFPreferencesSetValue(CFSTR("ApplicationAccessibilityEnabled"), kCFBooleanFalse, accessibilityDomain, kCFPreferencesAnyUser, kCFPreferencesAnyHost);
CFRelease(accessibilityDomain);
}
}
[autoreleasePool drain];
}
I don´t know what I´m doing wrong, maybe I'm sitting here way too long on my project. However, I set up a settings menu in my menuScene and I want to create a simple on-off button with a texture with this code:
if ([settingsMenuNode.name isEqualToString:#"checkmark1"]) {
if (self.checkmarkBanner == NO) {
[self.menuCheckmark1 setTexture:[SKTexture textureWithImageNamed:#"menuCheckmark"]];
self.checkmarkBanner = YES;
NSLog(#"YES");
}
if (self.checkmarkBanner == YES) {
[self.menuCheckmark1 setTexture:[SKTexture textureWithImageNamed:#"menuCheckmarkEmpty"]];
self.checkmarkBanner = NO;
NSLog(#"NO");
}
}
every time I touch on the node, I get both logs for ON & OFF at the same time.
can anyone please help me out?
checkmarkBanner is my BOOL just to set whether a banner notification during the game appears or not.
ok, thank you for your quick answers, so i´ve updated my code to this (i added some NSUserDefaults):
//CheckMarkBanner
if ([settingsMenuNode.name isEqualToString:#"checkmarkBanner"]) {
if (self.checkmarkBanner == YES) {
[self.menuCheckmark1 setTexture:[SKTexture textureWithImageNamed:#"menuCheckmarkEmpty"]];
NSString *offString = #"NO";
[[NSUserDefaults standardUserDefaults]setObject:offString forKey:#"checkmark1Banner"];
self.checkmarkBanner = [[[NSUserDefaults standardUserDefaults]stringForKey:#"checkmark1Banner"]boolValue];
NSLog(#"Banner NO");
}
else {
[self.menuCheckmark1 setTexture:[SKTexture textureWithImageNamed:#"menuCheckmark"]];
NSString *onString = #"YES";
[[NSUserDefaults standardUserDefaults]setObject:onString forKey:#"checkmark1Banner"];
self.checkmarkBanner = [[[NSUserDefaults standardUserDefaults]stringForKey:#"checkmark1Banner"]boolValue];
NSLog(#"Banner YES");
}
}
I have a NSTableView which I dynamically add columns. I've just added a call to setDataCell to customize my cell. The code looks like:
for(NSUInteger columnIndex = 0; columnIndex < resultSet.columNames.count; ++columnIndex)
{
NSTableColumn * newColumn = [[NSTableColumn alloc] initWithIdentifier: [NSString stringWithFormat: #"%ld", columnIndex]];
[newColumn.headerCell setAlignment: NSCenterTextAlignment];
[newColumn.headerCell setStringValue: resultSet.columNames[columnIndex]];
[newColumn setDataCell: [[HSDisclosureTextFieldCell alloc] init]];
[newColumn setEditable: YES];
[resultsTableView addTableColumn: newColumn];
if(newColumn.width < 60) [newColumn sizeToFit];
} // End of column loop
If I remove the call to setDataCell then I can still double click my entry and edit it.
I have minimized the HSDisclosureTextFieldCell contains the following (no overrides):
#interface HSDisclosureTextFieldCell : NSTextFieldCell
{
}
But I still cannot double click to edit the field anymore.
Any ideas where I'm going wrong?
Turns out even though I am doing:
[newColumn setEditable: YES];
and have:
- (BOOL)tableView:(NSTableView *)tableView shouldEditTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
implemented, I needed to switch my setDataCell to be:
HSDisclosureTextFieldCell * cell = [[HSDisclosureTextFieldCell alloc] init];
[cell setEditable: YES];
[newColumn setDataCell: cell];
Now that I have done that, everything seems to be working properly.
I need re-encoding a video file from photo library for web site service.
I tried below code but it has occurred error like 'video composition must have composition instructions'.
(code)
AVAsset *anAsset = [[AVURLAsset alloc] initWithURL:videoFileUrl options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:anAsset];
if ([compatiblePresets containsObject:AVAssetExportPresetMediumQuality]) {
self.exportSession = [[AVAssetExportSession alloc]
initWithAsset:anAsset presetName:AVAssetExportPresetPassthrough];
AVMutableComposition* mixComposition = [[AVMutableComposition alloc] init];
AVMutableCompositionTrack *firstTrack = [mixComposition addMutableTrackWithMediaType:AVMediaTypeVideo preferredTrackID:kCMPersistentTrackID_Invalid];
[firstTrack insertTimeRange:CMTimeRangeMake(kCMTimeZero, anAsset.duration) ofTrack:[[anAsset tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] atTime:kCMTimeZero error:nil];
AVMutableVideoCompositionLayerInstruction *FirstlayerInstruction = [AVMutableVideoCompositionLayerInstruction videoCompositionLayerInstructionWithAssetTrack:firstTrack];
AVMutableVideoCompositionInstruction * MainInstruction = [AVMutableVideoCompositionInstruction videoCompositionInstruction];
MainInstruction.layerInstructions = [NSArray arrayWithObjects:FirstlayerInstruction,nil];
AVMutableVideoComposition *MainCompositionInst = [AVMutableVideoComposition videoComposition];
MainCompositionInst.frameDuration = CMTimeMake(1, 30); // bit rate
MainCompositionInst.renderSize = CGSizeMake(640, 480); // frame rate
[self.exportSession setVideoComposition:MainCompositionInst];
NSURL *furl = [NSURL fileURLWithPath:self.tmpVideoPath];
self.exportSession.outputURL = furl;
self.exportSession.outputFileType = AVFileTypeQuickTimeMovie;
CMTime start = CMTimeMakeWithSeconds(self.startTime, anAsset.duration.timescale);
CMTime duration = CMTimeMakeWithSeconds(self.stopTime-self.startTime, anAsset.duration.timescale);
CMTimeRange range = CMTimeRangeMake(start, duration);
self.exportSession.timeRange = range;
self.trimBtn.hidden = YES;
self.myActivityIndicator.hidden = NO;
[self.myActivityIndicator startAnimating];
[self.exportSession exportAsynchronouslyWithCompletionHandler:^{
switch ([self.exportSession status]) {
case AVAssetExportSessionStatusFailed:
NSLog(#"Export failed: %#", [[self.exportSession error] localizedDescription]);
break;
case AVAssetExportSessionStatusCancelled:
NSLog(#"Export canceled");
break;
default:
NSLog(#"NONE");
dispatch_async(dispatch_get_main_queue(), ^{
[self.myActivityIndicator stopAnimating];
self.myActivityIndicator.hidden = YES;
self.trimBtn.hidden = NO;
[self playMovie:self.tmpVideoPath];
});
break;
}
}];
}
}
without the changing frame rate and bit rate, it works perfectly.
Please give me any advise.
Thanks.
Framerate I'm still looking for, but bitrate has been solved by this drop in replacement for AVAssetExportSession: https://github.com/rs/SDAVAssetExportSession
Not sure but some things to look at. Unfortunatley the error messages dont tell you much in these cases in AVFoundation.
In general, I would make things simple and slowly add functionality.To start, make sure all layers start at zero and then end at the final duration. Do the same for the main composition. Invalid times may give you an error like this. For your instruction, make sure that it starts at the same time and ends at the same time too.
I have a Mac OS X Document based app that has multiple NSViewControllers that I switch between and each view displays data from plist files in NSTableViews based on the user selections in the previous NSViewController's NSTableView. The problem I have is that I can't figure out what function can be called, every time a NSViewController gets loaded, to read the correct data from a file to display in the NSTableView. For UIViewControllers I used the function family of viewDidLoad, viewWillAppear, but I haven't been able to find the corresponding functions for NSViewController.
Currently I am using awakeFromNib, which works fine, but only the first time the NSViewController gets loaded. I've tried loadView, but that collapses the NSView. I assume that I need to do more setup to use loadView.
I'm using the View Swapping code from Hillegass's book Cocoa Programming for MAC OS X which switches ViewControllers with the following code:
- (void)displayViewController:(ManagingViewController *)vc
curBox: (NSBox *)windowBox
{
// End editing
NSWindow *w = [windowBox window];
BOOL ended = [w makeFirstResponder:w];
if (!ended) {
NSBeep();
return;
}
NSView *v = [vc view];
NSSize currentSize = [[windowBox contentView] frame].size;
NSSize newSize = [v frame].size;
float deltaWidth = newSize.width - currentSize.width;
float deltaHeight = newSize.height - currentSize.height;
NSRect windowFrame = [w frame];
windowFrame.size.height += deltaHeight;
windowFrame.origin.y -= deltaHeight;
windowFrame.size.width += deltaWidth;
[windowBox setContentView:nil];
[w setFrame:windowFrame
display:YES
animate:YES];
[windowBox setContentView:v];
// Put the view controller in the responder chain
[v setNextResponder:vc];
[vc setNextResponder:windowBox];
}
and puts the NSView Controller in the responder chain.
Is there some function I can call to setup the view every time I swap NSViewControllers? Can I check that a NSViewController has become the firstResponder?
This post provided the answer.
I added the following code:
- (void)viewWillLoad {
}
- (void)viewDidLoad {
}
- (void)loadView {
[self viewWillLoad];
[super loadView];
[self viewDidLoad];
}
and at the beginning of displayViewController I added
[vc loadView]