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.
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?
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;
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 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.
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.
I have an app in which I render local HTML files in a UIWebView. The files, however, are sometimes large, and getting to where you want takes a long time with the default scroll speed. Is there any way to boost up the vertical scroll speed of a UIWebView?
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.
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 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.
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?
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?
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.
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'm having some problem trying to present a modal view controller after it has been presented the first time, so I just start a little test method, it presents, dismisses and presents again the same controller modally.
// This is just test Code.
MYViewController *vc = [[MYViewController alloc] init];
[self presentModalViewController:vc animated:YES];
[self dismissModalViewControllerAnimated:YES];
[self presentModalViewController:vc animated:YES];
I get the error:
2011-11-15 09:50:42.678 Proyecto3[1260:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <RootViewController: 0x6d9d090>.'
The documentation does not add any clue here.
I'm wanting to create a view (UIControl) which blocks all input and shows a UIActivityIndicatorView while authenticating a user.
The UIActionSheet and UIAlertView both manage to add a black semi-transparent view over the top of all other views to block input and I'd like to do similar.
I've tried adding my view to the top UIWindow in the [[UIApplication sharedApplication] windows] array, and while this does place it above the UIKeyboard if it's visible, it doesn't place it over the StatusBar (which makes sense).
My next attempt was to extend UIAlertView, remove all of its subviews and set its layer.contents = nil, then add the ActivityIndicator as a subview. This works well, but I can't seem to kill the default bouncy transition of the UIAlertView when you call it to "show".
Does anyone have any pointers towards the best way tackle this problem that gives me full control?
Oh and I know blocking input is not great but I do ensure it's for a short period of time and it has the benefit of making it clear to the user that their action, which must complete for them to progress, is processing.
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
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 have a UIBarButtonItem opening an action sheet to offer users choices about what to do. Everything works as expected unless I try to click on the "Cancel" button. The target of the button appears to have moved up from where it should be. I can only activate it by clicking somewhere in the middle of the "Cancel" and "Ok" buttons.
I've tried at action sheets in other applications and they work fine, so it's not just my big thumb. The action sheet is opening in a UIViewController
- (void)showOpenOptions
{
UIActionSheet *sheet = [[UIActionSheet alloc]
initWithTitle:NSLocalizedString(@"Open link in external application?", @"Open in external application")
delegate:self
cancelButtonTitle:NSLocalizedString(@"Cancel", @"Cancel")
destructiveButtonTitle:NSLocalizedString(@"Open Link", @"Open Link")
otherButtonTitles:nil];
[sheet showInView:self.view];
[sheet release];
}
I have the following code to create a UIPickerView:
pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0f, 416.0f - height, 320.0f, height)];
pickerView.delegate = self;
pickerView.showsSelectionIndicator = YES;
[pickerView setSoundsEnabled:YES];
I would like to change the component widths and change the text size in each component. Is it possible to do this?
Thanks!
I have a custom UITableViewCell which I have created in IB. My labels display when I don't over-ride:
- (CGFloat)tableView:(UITableView *)tblView heightForRowAtIndexPath:(NSIndexPath *)indexPath
however my content is squished. I want the height to be 120px so I have the following:
- (CGFloat)tableView:(UITableView *)tblView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{ CGFloat rowHeight = 120;
return rowHeight;
}
I'm not sure why the content inside of my UITableViewCell all of a sudden disappears?
Hello,
I want to add a resize function to my app which works like the integrated copy feature on the iPhone. When the user opens the view he should see the image with the four blue dots which enable him to resize it. Is there an available example for this? Or has anyone the keywords for this functionality, which i can use for my further Search?
Thanks for all tips and hints
I am curious if there is a good reason I should / should not be using @synthesize for the tabBarController below, or does it not matter?
@implementation ScramAppDelegate
@synthesize window;
@synthesize tabBarController;
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self setTabBarController:[[UITabBarController alloc] init]];
[window addSubview:[tabBarController view]];
[window makeKeyAndVisible];
return YES;
}
-(void)dealloc {
[tabBarController release];
[self setTabBarController: nil];
[window release];
[super dealloc];
}
OR
@implementation ScramAppDelegate
@synthesize window;
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
tabBarController = [[UITabBarController alloc] init];
[window addSubview:[tabBarController view]];
[window makeKeyAndVisible];
return YES;
}
-(void)dealloc {
[tabBarController release];
[window release];
[super dealloc];
}
cheers Gary
I am using push scene to get the next scene. But, I read that for each PushScene the scene is stored in stack. The memory usage is more. So, I am using the replaceScene in place of pushScene. But, with replace scene I am getting the memory-bad-access message in debugger.
So, I want to popScene after using it, so that the retain count is zero. But, I am confused in using popScene.
If I have a Scene1 and Scene2. I used the following to go in to Scene2. Now I need to remove Scene1 from stack.
[[CCDirector sharedDirector] pushScene:Scene2];
Where should I write the popScene to popScene1. How to get the previous scene in current running scene ?
Thank you/
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