How/where in the code does the nib file get related to its *.m and *.h files?
Specifically I'm talking about when you create a new Objective-C class, not using the initWithNibName method.
I'm trying to figure out how to calculate where the scrollview will stop when a user does a swipe gesture and the scrollview goes into deceleration. I'm trying to use the delegate functions, but I can't accurately figure it out. Please help!
- (void) scrollViewDidScroll:(UIScrollView *)scrollView;
- (void) scrollViewWillBeginDecelerating:(UIScrollView *)scrollView;
- (void) scrollViewDidEndDecelerating:(UIScrollView *)scrollView;
Hi,
I have one problem let assume A and B are 2 view controller from A user push to B view controller,In B user starts some download by creating object C(which is NSObject class) and sets B as delegate to C(assign),now user want go back to A then dealloc of B calls object releases, C delegate fails to give call back(crashes).I want to get call and allow user to move to other view controller thats way i am retain the delegate in C class but retain of delegate is wrong ...
what are all solutions ...
Thanks in Advance.
I am trying to load a video from the web, but am having trouble getting it to appear in QuickTime. I can only hear the audio. I would like it to launch QuickTime.
- (void)loadView {
NSURL *movieURL = [NSURL URLWithString:@"http://movies.apple.com/media/us/mac/getamac/2009/apple-mvp-biohazard_suit-us-20090419_480x272.mov"];
if (movieURL != nil) {
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayer.initialPlaybackTime = -1.0;
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerScalingModeDidChangeNotification
object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(endPlay:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.movieControlMode = MPMovieControlModeDefault;
moviePlayer.backgroundColor = [UIColor blackColor];
[moviePlayer play];
}
}
I am calling a method that goes in a background thread:
[self performSelectorInBackground:@selector(loadViewControllerWithIndex:) withObject:[NSNumber numberWithInt:viewControllerIndex]];
then, I have this method implementation that gets called by the selector:
- (void) loadViewControllerWithIndex:(NSNumber *)indexNumberObj {
NSAutoreleasePool *arPool = [[NSAutoreleasePool alloc] init];
NSInteger vcIndex = [indexNumberObj intValue];
Class c;
UIViewController *controller = [viewControllers objectAtIndex:vcIndex];
switch (vcIndex) {
case 0:
c = [MyFirstViewController class];
break;
case 1:
c = [MySecondViewController class];
break;
default:
NSLog(@"unknown index for loading view controller: %d", vcIndex); // error
break;
}
if ((NSNull *)controller == [NSNull null]) {
controller = [[c alloc] initWithNib];
[viewControllers replaceObjectAtIndex:vcIndex withObject:controller];
[controller release];
}
if (controller.view.superview == nil) {
UIView *placeholderView = [viewControllerPlaceholderViews objectAtIndex:vcIndex];
[placeholderView addSubview:controller.view];
}
[arPool release];
}
Althoug I do create an autorelease pool there for that thread, I always get this error:
2009-05-30 12:03:09.910 Demo[1827:3f03] *** _NSAutoreleaseNoPool(): Object 0x523e50 of class NSCFNumber autoreleased with no pool in place - just leaking
Stack: (0x95c83f0f 0x95b90442 0x28d3 0x2d42 0x95b96e0d 0x95b969b4 0x93a00155 0x93a00012)
If I take away the autorelease pool, I get a whole bunch of messages like these. I also tried to create an autorelease pool around the call of the performSelectorInBackground:, but that doesn't help.
I suspect the parameter, but I don't know why the compiler complains about an NSCFNumber. Am I missing something?
My Instance variables are all "nonatomic". Can that be a problem?
UPDATE: I may also suspect that some variable has been added to an autorelease pool of the main thread (maybe an ivar), and now it trys to release that one inside the wrong autorelease pool? If so, how could I fix that? (damn, this threading stuff is complex ;) )
In my iPhone App I'd like to draw a few formulas. How can I manage that with quartz 2d? Is there a way to build formulas like for example in latex? Or are there any existing frameworks? Thanks.
When a UITextField with custom frame (200 × 54 px) loses focus, the text looks a little bit blurry.
example screenshot
Is this a common problem? Any workaround / solution or am I doing something wrong?
I have a CATiledLayer within a UIView and the UIView also contains a subview.
How can I make sure that the subview is always drawn above the layer?
Most of the time I get the tile layer covering the subview.
I have several text fields in a custom uiviewcontroller subclass, which is displayed within a popover. The popover is displayed form a bar button. I want the keyboard to go down when the popover is dismissed (either by the user tapping the bar button again, or tapping outside the popover. From the view controller that displays the popover, when the popover is dismissed, in either of the 2 fashions, I call
[optionsController dismissFirstResponder];
Optionscontroller is the uiviewcontroller subclass in the popover. Dismissfirstresponder is a method I defined:
-(void)dsimissFirstResponder {
[nameField resignFirstResponder];
[descriptionField resignFirstResponder];
[helpField resignFirstResponder];
}
Those are three IBoutlets which I connected in the xib to the text fields.
That doesn't work. Any help with this would be greatly appreciated.
In my application one player and 10 targets are there. Each target appears one after the other (from target1 to target10). It's a shooting game. If we hit the first target then second target will come. The targets have properties like name, speedOfGunDraw, probability to hit the player, speedOfFire.
What should I do to make them appear one after the other with these properties. I am using CCMenuItem for the target. I am using a sprite for the player. Please give me idea to do this.
Thank You.
What are all the file formats supported by UIWebView?
In my testing, I found that it supports XLS, DOC, PPT, PDF but not XLSX, and DOCX, RTF.
It supports image files like, JPG, PNG, GIF, BMP, not sure about TIFF or
Exactly, what all types are supported is not clear...
The UIWebView documentation also doesn't state it clearly.
Could someone please help?
Quick question if I may: I am just curious about the following (see below) Xcode says "initializer element is not constant" why this does not work, I guess its the NSArray ...
static NSArray *stuffyNames = [NSArray arrayWithObjects:@"Ted",@"Dog",@"Snosa",nil];
and this does ...
static NSString *stuffyNames[3] = {@"Ted",@"Dog",@"Snosa"};
gary
I'm trying link 40 buttons to one event handler method and then do the
processing work from one method instead of 40. I know how to link it
but once I get there I don't know how to distinguish what button was
pressed. Does anyone know how to reference the button object sender id
or is there another way to solve this problem?
Any help would be greatly appreciated.
How can I enter RGB or Hex color values for backgrounds in Interface Builder? I can select predefined colors but I would like to manually enter in RGB values. Where can I do this?
I'm building a carArray and want to filter the contents conditionally, using an NSPredicate, like so:
NSPredicate *pred;
switch (carType) {
case FreeCar:
pred = [NSPredicate predicateWithFormat:@"premium = NO"];
break;
case PremiumCar:
pred = [NSPredicate predicateWithFormat:@"premium = YES"];
break;
default:
pred = [NSPredicate predicateWithFormat:@"SOME PREDICATE THAT RETURNS EVERYTHING"];
break;
}
self.carArray = [aCarArrayIGotFromSomewhere filteredArrayUsingPredicate:pred];
My question is, what is the correct syntax for the value I've stubbed in as SOME PREDICATE THAT RETURNS EVERYTHING which returns all of the instances in the array / set?
PS - I know the answer and will post it immediately, just sharing it for everyone's reference as an earlier search on SO did not yield the result.
I have a class WebServiceCaller that uses NSURLConnection to make asynchronous calls to a web service. The class provides a delegate property and when the web service call is done, it calls a method webServiceDoneWithXXX on the delegate.
There are several web service methods that can be called, two of which are say GetSummary and GetList.
The classes that use WebServiceCaller initially need both the summary and list so they are written like this:
-(void)getAllData {
[webServiceCaller getSummary];
}
-(void)webServiceDoneWithGetSummary {
[webServiceCaller getList];
}
-(void)webServiceDoneWithGetList {
...
}
This works but there are at least two problems:
The calls are split across delegate
methods so it's hard to see the
sequence at a glance but more
important it's hard to control or
modify the sequence.
Sometimes I want to call just GetSummary and not also GetList so I
would then have to use an ugly class-level
state variable that tells
webServiceDoneWithGetSummary whether
to call GetList or not.
Assume that GetList cannot be done until GetSummary completes and returns some data which is used as input to GetList.
Is there a better way to handle this and still get asynchronous calls?
Update based on Matt Long's answer:
Using notifications instead of a delegate, it looks like I can solve problem #2 by setting a different selector depending on whether I want the full sequence (GetSummary+GetList) or just GetSummary. Both observers would still use the same notification name when calling GetSummary. I would have to write two separate methods to handle GetSummaryDone instead of using a single delegate method (where I would have needed some class-level variable to tell whether to then call GetList).
-(void)getAllData {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getSummaryDoneAndCallGetList:)
name:kGetSummaryDidFinish object:nil];
[webServiceCaller getSummary];
}
-(void)getSummaryDoneAndCallGetList {
[NSNotificationCenter removeObserver]
//process summary data
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getListDone:)
name:kGetListDidFinish object:nil];
[webServiceCaller getList];
}
-(void)getListDone {
[NSNotificationCenter removeObserver]
//process list data
}
-(void)getJustSummaryData {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getJustSummaryDone:) //different selector but
name:kGetSummaryDidFinish object:nil]; //same notification name
[webServiceCaller getSummary];
}
-(void)getJustSummaryDone {
[NSNotificationCenter removeObserver]
//process summary data
}
I haven't actually tried this yet. It seems better than having state variables and if-then statements but you have to write more methods. I still don't see a solution for problem 1.
Even though Interface Builder is aware of a MyClass, I get an error when starting the application.
This happens when MyClass is part of a library, and does not happen if I compile the class directly in the application target.
Seems like a simple thing but I can't seem to find a way to do it.
I saw this but it doesn't seem to work:
NSDate *date = [NSDate dateWithNaturalLanguageString:@"07/17/07"];
It would be great to see a couple different methods.
Thanks,
Nick
Hi all,
What is the best way to store an MKCoordinateRegion using core data? I assume there is a way to convert this to binary data somehow??
Many thanks
Jules
Hi,
I am writing a small game in cocos2d. I am adding child
[ self addChild: sprite1];
Should I remove these before going to next scene by using
[self removeChild: sprite1 cleanup:YES];
Does it increase the performance in device ?
Thank You.
I have a card (a flashcard you could say)
What I can do:
On fingersweeping over the flashcard the card gets turned. It's happening by detecting
touchesBegan and touchesMoved and then I do stuff like
[UIView beginAnimations:@"View Flip" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
if (left) {
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft forView:self.flashCardView cache:YES];
}else{
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromRight forView:self.flashCardView cache:YES];
}
What I can't do (but want to):
I want to somehow drag the flip.
Imagine this, you have a flashcard and you think you know the answer, you start flipping the card around because you want to see if you are correct, but then... no stop... you hesitate, turn back the card to the way it was, rethink, get the real answer and then finally flip to see that you were right to hesitate.
Now I only have: once you start flipping, you can't stop it.
In the tableView:accessoryButtonTappedForRowWithIndexPath: selector, I want to update the backgroundColor of the cell.
I can get the UIViewTableCell using cellForRowAtIndexPath: but I'm not sure how I can update its background color. The code beliw doesn't seem to work.
[_tableView beginUpdates];
cell.backgroundColor = [UIColor grayColor];
[_tableView endUpdates];
Any suggestions?
I can access the value like this:
NSNumber* rotationZ = [myLayer valueForKeyPath:@"transform.rotation.z"];
But for some reason, if I try to KV-observe that key path, I get a compiler error. First, this is how I try to do it:
[myLayer addObserver:self forKeyPath:@"transform.rotation.z" options:0 context:nil];
The compiler tells me:
*** Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[
addObserver: forKeyPath:@"rotation.z"
options:0x0 context:0x528890] was sent
to an object that is not KVC-compliant
for the "rotation" property.'
what I don't get is, why I can access that z value by KVC key path, but not add an observer to it. Does this make sense?
How else could I observe the z value of that matrix? I don't care about the other values of the matrix. Only the z rotation. Any other way to access and observe it?