objective-c

Asynchronous request to the server from background thread

I've got the problem when I tried to do asynchronous requests to server from background thread. I've never got results of those requests. Simple example which shows the problem: @protocol AsyncImgRequestDelegate -(void) imageDownloadDidFinish:(UIImage*) img; @end @interface AsyncImgRequest : NSObject { NSMutableData* receivedData; i...

Disable iPhone table rows

Is there any way to disable the "selectibility" of a UITableView row? Example: I would like to make an appointment for a haircut at a certain time with a certain stylist. What gets displayed to a user is a list of times in half hour increments, but unavailable times are grayed out/unselectable. ...

Ask About NSMutableArray (alloc , arrayWithCapacity)

I have two functions which one should i use? Please explain the difference. A: - (NSMutableArray *)FunctionA:(int)count { NSMutableArray *a = [[NSMutableArray alloc] init]; for (int i = 0; i < count; i++) { [a addObject:[NSNumber numberWithInt:0] ]; } return [a autorelease]; } B: -(NSMutableArray *)FunctionB:(int)...

What are the advantages of use accessors to instances of IB elements?

Usually, when we have to link an interface element to a field of a class, we use the keyword 'IBOutlet' to inform the pre-copiler: @interface MyController : NSObject { IBOutlet NSWindow *theWindow; } and in the implementation we use directly the pointer theWindow to call methods of the class NSWindow! But what are the advantages ...

Controlling OSX windows

I'm trying to control windows of a foreign OSX applications from my application. I'd like to 1. move the windows on the screen 2. resize the windows on the screen 3. change the currently active window of the application 4. get the currently active window. (And I'd like to do this either through ObjC/C/C++ apis). What are the API calls ...

In Cocoa, how do you apply a QuartzComposer patch effect to an NSImage?

I'm not trying to create a series of QC effects, I just want to use the Tracer effect. Do I have to create the QC thing and then apply that, or can I call it directly in Cocoa? ...

Circular #import/@class problem in ObjectiveC

I'm going to use an example to properly illustrate my confusion. I can't quite wrap my head around this. In Cocoa touch, we have UIViewController and its subclass, UINavigationController. Now, UIVC has an ivar of type UINav, and to get around the circular import problem they use @class UINavigationController. I am assuming they then #im...

@property attribute for NSNumber?

In the following am I right (keeping in mind the NSNumber is an object) to use assign with NSNumber? @property(assign) NSNumber *mass; Also if I used retain I would need to add a release, but if I created the NSNumber with an alloc would I not need to release twice, once for retain and once for alloc? @property(retain) NSNumber *mass...

Get all days of any month with objective-c

A seemingly simple question...how can I return a list of days for any specified month? NSDate *today = [NSDate date]; //Get a date object for today's date NSCalendar *c = [NSCalendar currentCalendar]; NSRange days = [c rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:today]; I basically want to use tha...

Is it possible to share code betwee classes that does not have the same parent?

I have two classes that are already subclasses of a different parent (due to an external library I cannot change this). However I want to share some common code between them, say for example, code that handles an action after a popup dialog etc. How do I do this? ...

Taking picture with QTCaptureView

Is it possible to simply take a picture and save it somewhere using a QTCaptureView and Apple's built-in iSight? I've seen lots of tutorials on recording video but none on simply taking a picture. Any help or guidance is appreciated! Collin ...

In Cocoa, is there a way to programmatically resize a view (in this case a window) to fit all of it's subviews?

Think tic-tac-toe. You are creating the buttons in rows and columns and you want to set the width and height of the parent window (actually, the size of the window's contentView, right?). But maybe you want to sometimes use a 4x4 grid or 5x5, so you can't use a default window setting. I iterate and do math to determine the positioning o...

Updating UI when model is changed

I have a series of UITableViewCell elements with various UIControls to set model values. When I make a change to model, I am having difficulty finding a way to update the UITableViewCell that displays the calculated property from the model. I have placed the model in AppDelegate, and accessing it directly from RootViewController. ...

Cocoa WebView cross-thread access

I have a C++ class running in its own thread that needs to execute some javascript in a WebView that's part of a Cocoa app. I have the C++ app call a method in the Cocoa window's controller and it in turns runs the javascript, passing in the data. It seems to work part of the time, but crash a lot of the time as well (somewhere in WebVie...

Stopping a NSTimer

Okay, so, this code is pretty basic. The user inputs an answer into a textbox, if it equals "first + second" they get a point. Then, they have 5 seconds to answer the next math problem. If they do, the function "doCalculation" is run again, and they get another point. IF they don't, then the function "onTimer" is run, and shit hits t...

NSScanner memory leak

Hello, I'm at my first experiences with iPhone development. I wrote some basic code to test the NSScanner class, and now I was looking into the Leaks tool. It seems that this code is leaking, when in the detailed stack I double-click my last call (before Apple's stuff), the incriminated line is the commented. Can anyone help me to under...

`from QTKit import *` causes a 'FAILED TO establish the default connection to the WindowServer' in PyObjC application

I've been trying out PyObjC and I can't seem to get the QTKit imports to work. If I import QTKit like so: from QTKit import * I get a flood of errors: [Session started at 2009-11-13 21:03:49 -0600.] _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL. 2009-11-13 21:03:...

Iphone NSTimer Issue.

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the sound that i want it to. Now the problem is with the timer. I want the timer to start on the click on the same button, and the timer value wil...

Huge memory leak in NSBitmapImageRep

I have a method that analyzes pixel data inside an NSBitmapImageRep that is built from a CGImageRef. Here is the relevant code: CGImageRef ref; // omitted code for initializing ref NSBitmapImageRep *bitmapRep = [[NSBitmapImageRep alloc] initWithCGImage:ref]; uint32* bitmapPixels = (uint32*) [bitmapRep bitmapData]; // do stuff with bitma...

How should I do to pop all or Specific Number viewsController?

[self.navigationController popViewControllerAnimated:YES]; This code is to pop only one viewController. How should I do to pop all or Specific Number viewsController? ...