Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
lord funk
Feb 16, 2004

Is there a jump to the next / previous #pragma mark keystroke?

Adbot
ADBOT LOVES YOU

lord funk
Feb 16, 2004

What's the easiest way to implement a group of vertical sliders for something like this (excuse the hideous colors):



Each vertical box is a slider-style object. I want the user to be able to slide their finger across the range to set them all quickly. Should I subclass UISlider, or roll my own subview?

lord funk
Feb 16, 2004

So apparently the UIKeyboardWillShowNotification and UIKeyboardWillHideNotification notifications are called when the UIKeyboard is active and you rotate the iOS device. This is a bit weird, since the keyboard doesn't actually hide itself or show itself, but rotates just like a normal view. Now it's messing with my interface - I use the 'hide' notification to reset a UIScrollVIew content position, but it gets called every time I rotate now.

Anyone run into this before?

Edit: nevermind, just made a _isRotating bool to keep track of things. My orientation code is like a Rube Goldberg machine.

lord funk fucked around with this message at 14:49 on Apr 20, 2011

lord funk
Feb 16, 2004

A bit of coding livejournal bloggering ahead:

I just realized that my Model - View code could have been designed with much less code if I had used NSSets instead of NSArrays, and passed references of the Models to the Views. As it is now, I'm keeping track of array indexes and passing those back and forth instead to keep everybody attached to their corresponding Model / View.

What kills me is that my solution works perfectly well, and I would gain nothing by redoing it. I haaaate knowing that I chose the roudabout way of coding it, but it would be a waste of time to redo all of it. Nnnrrrhghghg....

lord funk
Feb 16, 2004

Anode posted:

If you want an excuse to redo it, there is something you'd gain: ease of maintenance.

Don't tempt me! :ohdear:

You're right, of course. Plus moving forward it would be easier to add to it. By my god. It's going to be a week of un-gluing this thing.

lord funk
Feb 16, 2004

Tux Racer posted:

Not only that, but NSSets are faster to reference than NSArrays.

Is this true for individual objects, or just when you iterate over the whole group? So using member: is faster than objectAtIndex:?

lord funk
Feb 16, 2004

chimz posted:

You should use whatever interface most matches the operations you're trying to perform, and let it worry about how to do that most optimally.

This was my original reason to make the switch to NSSet, but after a bit of research it's probably going to be just as hard to keep track of where my objects are than my silly index following system. I think I have a better idea of when to use which now, but for this program it's not worth the redesign.

lord funk
Feb 16, 2004

Finally got an iPad for development. :dance:

Is there a way to disable scroll touches in certain areas of a uiscrollview? I have vertical sliders that keep triggering the scroll action instead of changing the slider value. They're all together in a big group, so maybe I can just define a rect area that won't pass the touch to the scroll action. Anyone done this before?

Edit: it might work to put the sliders in their own uiscrollview which has scrolling disabled.
Edit: it doesn't.

lord funk fucked around with this message at 15:19 on May 2, 2011

lord funk
Feb 16, 2004

fankey posted:

Subclass UIScrollView and override touchesShouldBegin:withEvent:inContentView and return YES if you want the UIView that was touched to get it. Since you probably want quick response on your slider make sure to turn off Delay Content Touches in the scroll view or you will have to press and hold for a brief moment before the touchesShouldBegin will be called.

Actually, delay content touches solves the problem completely. The only downside is exactly why it's there in the first place, which is that the rest of the uiscrollview is full of buttons and sliders that catch the touch when you DO want to scroll.

I'll live with it, though. MOVING FORWARD NOW...

lord funk
Feb 16, 2004

I added some tab buttons to quickly jump between text boxes, but they react horribly when you try and use them. If you type in a number, then quickly tap the tab button, it 'corrects' your tap and presses 'Delete' instead.



This is kind of annoying, since the point of the tab buttons was to speed up data entry. Is there a way to force the tab button layer to get tap preference?

lord funk
Feb 16, 2004

Ender.uNF posted:

Well it turns out my app crashes on iPod Touch 4G devices... no clue why, it works on iPad 2, iPhone 4, and iPhone 3GS.

*sigh* I ordered an iPod Touch today so I can track this down.

I know why! At least, if it's the same issue I had.

You need to explicitly generically find the 'Main nib file base name' if its a universal application. I had no idea about this, and only had the (iPhone) and (iPad) nib files set. I figured the iPod would find the (iPhone) setting and use that (it doesn't).

Only registered members can see post attachments!

lord funk
Feb 16, 2004

How can I monitor how hard the iPhone processor is working while my app runs?

lord funk
Feb 16, 2004

Small White Dragon posted:

"Instruments" can do it.

Oh :doh: why didn't I think of that.

lord funk
Feb 16, 2004

Hacky question ahoy:

Is there a way to do a find / replace on a .txt file while an iOS app is running? As in, part of my app loads data from "thefile.txt" and before it does so I want to find / replace a series of strings.

If that's possible it will save me miles of work.

lord funk
Feb 16, 2004

OHIO posted:

You can write to your /documents folder inside your app. So on the first run, copy 'thefile.txt' to your /documents, then always load that file from /documents and edit it as necessary.

Great - thanks.

lord funk
Feb 16, 2004

What's the trick to getting nice clean numbers to appear in UITextFields? I'd like to set a digit limit, then get results like:

1234.5
12.432
13
14.002
0.001

So things like:
- max 3 decimal places
- drop decimals of zero
- close enough? be an int
- max digit limit drops decimals

This is just for display. Is there an easy trick I'm missing, or do I need to start messing with the [NSNumber stringValue]? I want to completely eliminate the ellipsis from being shown.

lord funk
Feb 16, 2004

Flobbster posted:

You may want to look at the NSNumberFormatter class.

Brilliant, thanks.

lord funk
Feb 16, 2004

Small White Dragon posted:

WWDC 2011 videos are up.

Yesss. I don't think my wife understands why I want to watch videos of people giving powerpoint presentations, but I love these videos.

lord funk
Feb 16, 2004

Could someone play professor for a minute and :eng101: me about how to use ViewControllers correctly? I've made a bunch of beginner mistakes in my current app (putting logic data in UIViews, for example). I've researched Model-View-Controller by reading up on it on the dev site, and watching some WWDC videos.

But... in the WWDC 2010 Session 116 video (about 45:00 in), the presenter says that it's preferable to use multiple view controllers to keep views / data well paired, rather than have one giant mega view controller -- even in the context of one screen on the iPad. Everywhere I look, though, Apple says to use one view controller per screen.

So here's a stripped down version of my design:



The ViewController is becoming massive. Not only is it handling the display of all the custom subviews (there are dozens of them to be shown / not shown), but it's also acting as the delegate for the interactions within them.

Here is what I *think* the video is proposing:



Is this
1) possible, and if so, how?
2) wise?
...or am I way off?

lord funk
Feb 16, 2004

echobucket posted:

I can see if for professional audio type applications though....

Bingo.

lord funk
Feb 16, 2004

Alright, thanks. There's always a lingering feeling that your doing it wrong when you teach yourself this stuff.

lord funk
Feb 16, 2004

Does it bum anyone else out that there isn't a good Number Pad keyboard mode for the iPad? I really don't want to give in and roll my own, but my god, the full keyboard takes up sooooo much space. :(

lord funk
Feb 16, 2004

I've got a view updating problem. I have a method in my view's delegate that updates some slider colors, which works as expected (the user interacts with the interface, the other sliders update to reflect the change).

But I also want that view to follow a value through key-value observing. I set up the KVO in the view controller (the view's delegate) and it follows the value perfectly. So I pass that value to the method, but the view doesn't update.

I thought I might need [UIView setNeedsDisplay], but I've put that everywhere I can think and still nothing. Why is calling the method with KVO different than calling it with a user interaction?

lord funk
Feb 16, 2004

The view's (called SEQView) methods that updates the start position, and the one that sets the background colors for a group of UISliders:

code:
//in SEQView.m

- (void)setSeqStartPosition:(int)startIndex {
    _seqStartPosition = startIndex;
}

- (void)updateSeqRangeDisplay {
    //update slider backgrounds
    [UIView beginAnimations:@"replaceSlidersForNewBank" context:nil];
    [UIView setAnimationDuration:0.0];
    for (int i=0; i<16; i++) {
        int seqIndex = (_currentBank * 16) + i;
        if (seqIndex < (_seqLength + _seqStartPosition) &&
            seqIndex >= _seqStartPosition) {
            TCSlider *slider = [_seqSliders objectAtIndex:i];
            [slider setBackgroundColor:[UIColor greenColor]];
        } else {
            TCSlider *slider = [_seqSliders objectAtIndex:i];
            [slider setBackgroundColor:[UIColor grayColor]];
        }
    }
    [UIView commitAnimations];
}
The view's delegate method that gets called when one of the view's sliders is moved:

code:
//in SEQViewController.m

- (void)ugViewDidChangeParameter:(int)parameter toValue:(id)value forUG:(int)ugIndex {    
    //for seq view, test for start change (to trigger view update)
        if (ugIndex == [[[sharedCC liveSEQs] objectAtIndex:i] startPositionUGIndex]) {
            switch (parameter) {
                case kUGConstValueParameter:
                case kUGMinValueParameter:
                {
                    [[_SEQViews objectAtIndex:i] setSeqStartPosition:[value intValue]];
                }
                    break;
                case kUGControllerAndCategoryParameter:
                {
                    if ([[value objectAtIndex:1] intValue] == kConstantCategory) {
                        int startPosition = [[[sharedCC liveUGs] objectAtIndex:ugIndex] constValue];
                        [[_SEQViews objectAtIndex:i] setSeqStartPosition:startPosition];
                    } else {
                        int startPosition = [[[sharedCC liveUGs] objectAtIndex:ugIndex] maxValue];
                        [[_SEQViews objectAtIndex:i] setSeqStartPosition:startPosition];
                    }
                }
                    break;
                default:
                    break;
            }
            //update range display
            [[_SEQViews objectAtIndex:i] updateSeqRangeDisplay];
        }
    }
}
The same delegate has this method that key-value observes a value, and calls the same updateSeqRangeDisplay method:

code:
//in SEQViewController.m

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    if ([keyPath isEqualToString:@"currentSeqIndex"]) {
        NSNumber *newVal = [change valueForKey:NSKeyValueChangeNewKey];
        if (_currentContentTab == kSEQContentTab) {
            for (int i=0; i<[_SEQViews count]; i++) {
                SEQView *sv = [_SEQViews objectAtIndex:i];
                [sv setSeqStartPosition:[newVal intValue]];
                [sv updateSeqRangeDisplay];
            }
        }
    }
}
The KVO method will call updateSeqRangeDisplay, and it runs with the new value, but nothing in the display changes.

lord funk
Feb 16, 2004

If you want a simplified version, I swapped out the slider display function for this much simpler test:

code:
//in SEQView.m

- (void)testDisplayUpdate:(int)index {
    [testLabel setText:[NSString stringWithFormat:@"%i",index]];
    NSLog(@"testDisplayUpdate %i",index);
}
It should just change the text of a label, but it doesn't. It will print out the right value though.

lord funk
Feb 16, 2004

pokeyman posted:

Nothing obvious jumps out at me. Are you sending messages to views from the main thread?

Yes. Do you think the KVO is working on another thread or something?

I've been playing further, and it will will sometimes update the view when the view first loads (but only then sometimes). Or, with the slider color method, if you set the color manually it will 'fight' the KVO value and try and update both of them. But at least it's updating! If I can just figure out why.

lord funk fucked around with this message at 23:46 on Jul 16, 2011

lord funk
Feb 16, 2004

Doc Block posted:

KVO is supposed to be synchronous AFAIK, but that doesn't necessarily mean the observer gets called on the same thread.

Try performSelectorOnMainThread, so your observe method would instead do
code:
[sv performSelectorOnMainThread:@selector(setSeqStartPosition:) withObject:[newVal integer] wait:YES];
[sv performSelectorOnMainThread:@selector(updateSeqRangeDisplay) withObject:nil wait:NO];
or something.

edit: or maybe you have conflicting key-value observations

OH YES. *fist pump*

Thanks Doc, pokey.

lord funk
Feb 16, 2004

KidDynamite posted:

Are there any new books out that deal with Xcode 4? Since Lion is not compatible with Xcode 3.

If you use an older book, Googling things that are in the wrong place can fill in the blanks. Either way, books are no substitute for this thread. Case in point:

Toady posted:

By the way, you should be using the context argument and calling super if there's no match (explained here).

You guys are awesome.

lord funk
Feb 16, 2004

Ender.uNF posted:

Keep receipts/bills and track everything. You will save a bunch of money come tax time.

You do need to get a good accountant. I didn't get anything until I found a guy that knows how tax law works for musicians. It is tricky, though. For example, the 'spare room' thing is true if it is only used for business, and since it's based on square footage, you can't just start deducting the living room.

Do you all do tax withholdings with your payments from Apple, or not?

lord funk
Feb 16, 2004

Is the lag between touch event and drawing unavoidable?



This is a new OpenGL ES project, with a simple draw frame that draws a circle for each touch point. drawFrame is running of an NSTimer. I tried pushing the drawFrame method only when touches were updated - but there was a noticeable bottleneck when lots of touches updated quickly (the frames would get backed up, then catch up as fast as they could).

Is there a trick out there to avoid this? I'm drawing 2D only, simple geometric shapes.

lord funk
Feb 16, 2004

Doc Block posted:

What interval are you using for the NSTimer? Have you tried using DisplayLink instead?

Now that I take a closer look, it is running off of DisplayLink, with the interval set to 1 (I think this means its updating 60x / sec).

Google is telling me that this is expected behavior, but I didn't know if there was any sorcery out there to tighten it up.

lord funk
Feb 16, 2004

Doc Block posted:

Try NSTimer with the interval set to something fast like 1/240. I've heard of people having issues with touches and DisplayLink.

It has the same result. Also, NSTimers can effectively fire at a maximum 1/50 - 1/100 second.

I've been toying with predicting where the touch should be by watching the change in coordinates, and adding that to the requested x/y position. It works, but it's jittery. Might be something in there, though.

lord funk
Feb 16, 2004

Is Xcode 4.1 more stable than 4.0.2? I've been sitting at 4.0.1 for a while and I'm reluctant to upgrade (for no reason other than preventing headaches), but it is crashing constantly.

lord funk
Feb 16, 2004

Is this what you mean?



Because I'm getting that about 60% of the time I hit run. Full on hang, force quit, reopen, clean, build, run. And this is after insignificant or no changes to the code.

lord funk
Feb 16, 2004

lord funk posted:



Because I'm getting that about 60% of the time I hit run. Full on hang, force quit, reopen, clean, build, run. And this is after insignificant or no changes to the code.

I upgraded to Xcode 4.0.2 (still on Snow Leopard), and it is still happening. It is getting absolutely out of control.

Does anyone have an idea of how I can troubleshoot this? I don't even have any compiler warnings.

lord funk
Feb 16, 2004

I have 4 gigs of RAM.

I turned the GDB debugger off - that has stopped the problem. I don't have a debugger, but at least I can work a little more today. Tomorrow I'll reinstall Xcode.

lord funk
Feb 16, 2004

Not a question, just some idle optimization notes with my current app:

As suggested in a WWDC video, I moved all my graphics calls to a background thread to prevent it from tying up the main thread. It's not a graphics heavy app, but I shaved 30ms off the response time for UITouch events. In the audio world that is huge!

The other big gain was changing a message call from using NSString to a plain old char[]. The original call built an NSString, then it unpacked it into a const char*. That took 200% more work than the actual function of the call. That chopped off about 30-40% of the overall processing.

Edit: just confirmed, the responsiveness is the same whether the graphics are running or not. :dance:

lord funk fucked around with this message at 20:19 on Aug 6, 2011

lord funk
Feb 16, 2004

WWDC 2011 Session 418 - Best Practices for OpenGL ES on iOS

It doesn't go into too many specifics, but it points out some gotchas that you'll run into with thread safety.

lord funk
Feb 16, 2004

I cannot find any documentation about this behavior. I've added a UINavigationBar over a keyboard input, with two buttons that act as 'Tab' buttons to get to other textfields.

The problem is: the keyboard autocorrects touches away from the buttons. If you type a number, then (relatively) quickly press the kNext button, it will press Delete instead. And there's another button (kPrev) that simply won't respond until a second or two pause has happened after pressing a key.



HELP. I don't want to throw out this feature from the app, but as it stands it's unusable.

Edit: at one point, I put HUGE buttons quite some distance from the keyboard. It still acted the same way.

lord funk fucked around with this message at 01:24 on Aug 17, 2011

Adbot
ADBOT LOVES YOU

lord funk
Feb 16, 2004

I must have downloaded this example project, and now this pops up every time I open another project. I've deleted the repository again and again, but it always comes back. Where is this POS living?

Only registered members can see post attachments!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply