cocoa-touch

Programmatically pressing a UITabBar button in Xcode

Sorry for the newbie question. I have a UITabBar in my main window view as well as an array of UINavigationControllers for each Tab. The structure is similar to the iPod app in that the main views can be seen by selecting TabBar items and then the user can drill down further with the NavigationController by pushing views to the stack. ...

Are Database operations thread safe?

Hi, I am using sqlite in my iPhone app. I have some database operations, in which I have to insert into two tables different data(means there is no data-dependency). Can I perform these two operations in seperate thread. While the insert operation in each table are more than one. So I am doing this in a while loop also. ...

How to make a macro that takes a formatted string + several additional arguments, just like NSLog?

This is for practise. I try to build something similar to NSLog. Currently I have this: #define LogThis(info) \ [[MyLogger sharedLogger] logThis:info];\ - (void)logThis:(NSString*)info { fprintf(stderr, [[NSString stringWithFormat:@" %@\n", info] cString]); } Currently all I can do is pass a simple @"string" to it, but no f...

UIView isn't released. Calling delegate with self, and using UIView commitAnimations adds retain count

I have a view that is added as a subview in a viewcontroller. The subview has delegates methods and the viewcontroller is assinged as its delegate. The subview has a animation and calls a delegate method when the animation is finished. The problem is that when the viewcontroller is removed from the view by the navigationcontroller the s...

Is it possible to define a macro that looks almost like a comment?

I try to make a useful macro for logging. But I find that NSLog and all other sort of macros that carry textual information with them simply distract a lot from the code. Is there any way to "hack" Xcode in a way that it will interpret something like /*** do this because of that ***/ as a macro call, which results in calling NSLog, ...

How to let the debugger stop anywhere?

Example: I run my app in the simulator. Then I want to figure out what exactly is going on when I touch a button. Normally I would first have to find out where the entry-point of all this madness is in order to place a breakpoint. But now lets assume my app has 700 classes and it's incredibly complex, with more than 12.000 methods. Chanc...

How to pass all arguments of a method into NSLog?

For example, I print out something to the console using NSLog. Is there a way to pass all the current method's arguments to NSLog or any other function or method without looking at each of them explicitely? For example, I have already a macro that prints useful information to the console when I just put LOGME in my code. The macro will ...

Problem reading a string from an NSDictionary inside an NSMutableArray stored using NSKeyedArchiver.

I'm saving some data using a series of NSDictionaries, stored in an NSMutableArray and archived using NSKeyedArchiver. I'm basically trying to save the states of several instances the class 'Brick', so I've implemented a getBlueprint method like this (slimmed down version) -(id)getBlueprint { // NOTE: brickColor is a string NSD...

XCode breakpoint [NSExceptionRaise] vs -[NSExceptionRaise]

XCode:Run>Show>Breakpoints I've added the obligatory [NSExceptionRaise] and objc_exception_throw yet when I close the Breakpoints window and then return XCode adds a third breakpoint: -[NSExceptionRaise]. Does this mean [NSExceptionRaise] is wrong and I should delete it? Or are they both helpful? If so in what way are they functionally...

Why does Apple's GLGravity example become slow and unresponsive after touching the screen?

To reproduce the problem: Download Apple's sample project GLGravity: http://developer.apple.com/iphone/library/samplecode/GLGravity/index.html "Build and Go" on a device. Observe how smooth it is. Then, touch anywhere on the screen. Observe how jerky and slow it becomes. Eventually, it becomes unresponsive. Why? And how would you...

Detecting Swipe In UINavigationBar

I am trying to get my view controller to detect swipes in the UINavigationBar that is automatically displayed by my app, but it refuses to detect swipes. Is there any way I can do it? ...

How do I properly move an image using UIAccelerometer?

i have implementing moving image using UIAccelerometer.I have used below code. code: float gravX = (acceleration. x * kFilteringFactor) + (gravX * (1 - kFilteringFactor)); float gravY = (acceleration. y * kFilteringFactor) + (gravY * (1 - kFilteringFactor)); float moveX = acceleration. x - gravX; float moveY = acceleration. y - gravY; ...

NSDateFormatter gives different values on device and simulator? What is work around?

Hi, I am using NSDateFormatter, the problem is with its consistency. If I use the kCFDateFormatterMediumStyle it gives the format as "Nov 26, 2009" in simulator but on device it gives "26-Nov-2009". Now I have the question, Is this NSFormatter trustable means in near future or updates from apple can it change the style again? ...

Why won't MFMailComposeViewController send messages?

I am tring to send an email using xcode on Mac PC. For this I am using MFMailComposeViewController class and I have attached the code files: But when I click on send button of the modal view controller then it returns MFMailComposeResultSent object of MFMailComposeResult class but the email did not reach to the specified email id. When ...

Using -setValue:forKey: vs "object.var = ..."

The difference between these two lines of code is that the second is KVO compliant and the first isn't? [person setValue:tempPerson.name forKey:@"name"]; person.name = tempPerson.name; The reason I'm asking is because I need to update 60 attributes on over 500 objects, I don't want KVO notifications for more than a handful of attribut...

Why is using a static int in my accelerometer callback so much slower than using an instance variable?

I'm playing with the GLGravity example to figure out some of the performance nuances related to dealing with the accelerometer. Here's the problem code: - (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration { static int accelCallCount; accelCallCount++; if (accelCallCount % 100 ==...

UITextView autoscroll to last line

Hi *, When writing in a UITextView more text than can fit entirely inside it, the text will scroll up and the cursor will often place itself one or two lines above the view's bottom line. This is a bit frustrating as I want my application to make good use of the entire height of the text view. Basically what I want is to configure the ...

How to stub a class method in OCMock?

I often find in my iPhone Objective-C unit tests that I want stub out a class method, e.g. NSUrlConnection's +sendSynchronousRequest:returningResponse:error: method. Simplified example: - (void)testClassMock { id mock = [OCMockObject mockForClass:[NSURLConnection class]]; [[[mock stub] andReturn:nil] sendSynchronousRequest:nil ...

How does Urbanspoon display map?

I've looked at Google's map API, which is all javascript and terribly slow on the iPhone. I then tried using the link option available at maps.google.com. That is fast but I can't see having much control over it. It also displays a little search box at the top of the map. Google's API says you must use maps in a website, which the iP...

const vs static NSStrings in Objective-C

These lines are both in the implementation file above the @implementation declaration. NSString * const aVar = @"aVarStringValue"; static NSString *aVar = @"aVarStringValue"; As far as I understand, the second static is allocated once only within the lifetime of the application and this fact contributes to performance. But does this...