objective-c

Why does this TableView code work?

I made a typo when creating a UITableViewCell with this code: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CellIdentifier"; UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; ...

iPhone: How to Sync Data Between Two Tab View with One Button Action

Hello, I have an app which plays music files. The UI has two tab views. TabOne plays the song while TabTwo displays information about the song. I have a button which sets a global variable that identifies the song to be played. The song does play but the information displayed in TabTwo does not update. How do I ensure that both tabs u...

How to check if a BOOL is null?

Is there a way I can check to see if a value is NULL/Nil before assigning it to a BOOL? For example, I have a value in a NSDictionary that can be either TRUE/FALSE/NULL mySTUser.current_user_following = [[results objectForKey:@"current_user_following"]boolValue]; When the value is NULL I get the following error *** Terminating app ...

UIScrollView calls layoutSubviews() each time its scrolled

Hi, I subclassed UIScrollView (IPhone SDK) and overrode the (void)layoutSubviews; method. I noticed that each time the scrollView is scrolled, this method is called. Is that the correct behaviour or do I have mistakes in my code? If it is the default behaviour, isn't this a performance killer? Sincerely, heinrich ...

Objective-C x-code: Equivalent of __FILE__ and __LINE__ from C/C++?

Same question as: http://stackoverflow.com/questions/696218/do-line-file-equivalents-exist-in-c But for Objective-C in iPad/iPhone SDK Xcode? This would really help my NSLog statement be a lot more readable over time. ...

What does “foo = (foo + 1) % bar” exactly do?

From the Finch audio library: - (void) play { [[sounds objectAtIndex:current] play]; current = (current + 1) % [sounds count]; // this line here... } I try to grok it: There is a number of sounds n, and current is increased by 1 on every iteration. As soon as current is bigger than number of sounds n, the modulo returns zero. ...

How to find out if a method exists in Obj-C when given an NSString

I have a method as an NSString *. If it exists, I want to call it, and if not, do nothing. SEL eventSelector = NSSelectorFromString(eventSelectorStr); if ([delegate respondsToSelector:eventSelector]) { [delegate performSelector:eventSelector]; [delegate adapterDidFinishAdRequest:self]; } else { // Does not implement selector...

Is Objective C fast enough for DSP/audio programming

I've been making some progress with audio programming for iPhone. Now I'm doing some performance tuning, trying to see if I can squeeze more out of this little machine. Running Shark, I see that a significant part of my cpu power (16%) is getting eaten up by objc_msgSend. I understand I can speed this up somewhat by storing pointers to f...

How can an animator do animation targeted for the iPhone

Hi, I'm working with an animator for the iPhone. The animator I'm working with isn't a programmer and has a background in Flash. (right now she's doing the animation in Flash and I need to convert to Objective C). For some it's ok because I can just use image frames, but there are more complex animation that would take longer for me ...

How do I pass an NSString through 3 ViewControllers?

hey, I'm currently using the iPhone SDK and I'm having trouble passing an NSString through 3 views I am able to pass an NSString between 2 view controllers but I am unable to pass it through another one. My code is as follows... `- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)index`Path { NSStri...

iPhone simulator app crashes when appending a string

Hi, I'm a complete novice, so I'm probably missing something really easy, but I can't get my string appending to work. I add the 3rd character to typedDigit & it crashes - the method is called fine and typedDigit will get to 2 characters long. I think everything is declared properly in the header file. Code is - -(IBAction)digitPressed...

Attaching user data to AXObserver

I am using an AXObserver to monitor when a window is closed. In the callback, I am just raising an NSNotification. All working well. What is the correct syntax for attaching some user data as refcon? The working call looks like this: err6 = AXObserverAddNotification(observerTable, tableRef, kAXUIElementDestroyedNotification, nil); ...

Cocoa:Testing for the same object with ifs/switches

Ok so here's my code, it works great: - (void)textViewDidChange:(UITextView *)textView{ if (textView==someObject) { [detailItem setValue:textView.text forKey:@"someObjectAttribute"]; } The problem is that I have lots of textviews instances to test for and I would prefer to find some other way to consolidate the code. I was thinkin...

How to show file thumbnails?

Hello everybody, I got a TableView with a list of files in a directory. Now i want to add a colum with the file-thumbnails. How do i do this? ...

iPhone tableview: titleForHeaderInSection derived from array

I have a tableview that is populated by an array. Currently the tableview has no grouping. What I would like to do is check a value of each array object, such as State, and group all the CA items together, all the OR items together, etc. Then, assign those groups a title. The array is dynamic, and will grow and get new values in the ...

iPhone write to file (alternative directory)

New to iPhone 3.2, Apple introduced File-Sharing support. Details can be found at https://developer.apple.com/iphone/library/releasenotes/General/WhatsNewIniPhoneOS/Articles/iPhoneOS3_2.html#//apple_ref/doc/uid/TP40009337-SW1 . Now, most examples floating around in the web demonstrates writing to the documents directory. What if I wan...

In Cocoa, why won't a textfield be shown until after the IBAction is completely executed?

I have an IBAction with some simple code inside: -(IBAction)change:(id)sender { [textfield setHidden:NO]; [self dolengthyaction]; } 'textfield' is an NSTextField in a nib file, and -'dolengthyaction' is a function that takes about a minute to finish executing. My question is: Why isn't the textfield shown until AFTER "dolengt...

Resize font size in UITextView

Is there a way to shrink the font-size in a UITextView if there is too much text? Similar to the UILabel? ...

How to HIDE the iPad keyboard from a MODAL view controller?

I'm trying to hide the iPad keyboard from a modal view controller but it doesn't work. I have tried resignFirstResponder but that doesn't have any affect if we are in a modal view controller. I tried resignFirstResponder in a non-modal UINavigationController with the very same UIViewController and the keyboard hides correctly. Does anyo...

Beginner iPhone Controller Question

I have a view that only has a button UIButton. First time clicking the button will draw a square above the button and the second time will replace the square with a circle. I need some help on writing the controller code. Please guide me to the right path. Thanks ...