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
rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
Is point a Superclass* with the child method only declared on a subclass? Because you need to cast down to the subclass to make that type-check.

Adbot
ADBOT LOVES YOU

Eponym
Dec 31, 2007
I'm trying to learn Cocoa by creating a simple subclass of NSTableView, called LayoutView.

I've added it to my .nib via the CustomView placeholder in Xcode4's gui builder, and I've set the name of the class to LayoutView.

I've added the method awakeFromNib, and in it, I have the following code:
code:
- (void)awakeFromNib
{
    NSTableColumn* column = [[NSTableColumn alloc] initWithIdentifier:@"Hello"];
    [self addTableColumn:column];
    return;
}
When I run my project, I expect the LayoutView to have one column, with the header "Sunday". However, nothing appears at all. When I debug it through gdb, the command "p (int)[self numberOfColumns]" returns 1, so I know the column is there.

What am I missing? I haven't hooked LayoutView up to a data source yet. Is this necessary for the table to display at all, or am I missing something else?

Eponym fucked around with this message at 05:11 on Jun 21, 2011

Choadmaster
Oct 7, 2004

I don't care how snug they fit, you're nuts!

Eponym posted:

I'm trying to learn Cocoa by creating a simple subclass of NSTableView, called LayoutView.

I've added it to my .nib via the CustomView placeholder in Xcode4's gui builder, and I've set the name of the class to LayoutView.

I've added the method awakeFromNib, and in it, I have the following code:
code:
- (void)awakeFromNib
{
    NSTableColumn* column = [[NSTableColumn alloc] initWithIdentifier:@"Hello"];
    [self addTableColumn:column];
    return;
}
When I run my project, I expect the LayoutView to have one column, with the header "Sunday". However, nothing appears at all. When I debug it through gdb, the command "p (int)[self numberOfColumns]" returns 1, so I know the column is there.

What am I missing? I haven't hooked LayoutView up to a data source yet. Is this necessary for the table to display at all, or am I missing something else?

You might have better luck if you add an actual NSTableView to the nib, and set it's class to LayoutView.

Why are you subclassing NSTableView? You generally shouldn't do that without good reason. The setup code you have there would be more properly placed in a controller class (say, the NSWindowController subclass you use for the window your table view is in).

Also, you're leaking the table column. Read up on memory management (though maybe if you're using ARC now, that's okay because it's handled for you? gently caress me if I know).

Eponym
Dec 31, 2007

Choadmaster posted:

You might have better luck if you add an actual NSTableView to the nib, and set it's class to LayoutView.

Why are you subclassing NSTableView? You generally shouldn't do that without good reason. The setup code you have there would be more properly placed in a controller class (say, the NSWindowController subclass you use for the window your table view is in).

Also, you're leaking the table column. Read up on memory management (though maybe if you're using ARC now, that's okay because it's handled for you? gently caress me if I know).

I planned to create a view controller to handle the setup later; I was just trying to find the quickest way to visualize what I want.

I'm using garbage collection by setting the "Objective-C Garbage Collection" in the project settings to "required". I thought that was enough to not have to worry about retain/release.

I subclassed because I wanted to be able to draw a curve that spans across multiple columns of the TableView. Ideally, I'd like to be able to composite whatever the NSTableView draws with a view of the same size, containing some random bezier curve. I'm not clear on how exactly to get there, but I thought subclassing NSTableView was a logical first step.

If any of these reasons/methods sound like crap, sorry in advance.

Eponym fucked around with this message at 08:21 on Jun 21, 2011

Toady
Jan 12, 2009

Eponym posted:

I'm trying to learn Cocoa by creating a simple subclass of NSTableView, called LayoutView.

I've added it to my .nib via the CustomView placeholder in Xcode4's gui builder, and I've set the name of the class to LayoutView.

I've added the method awakeFromNib, and in it, I have the following code:
code:
- (void)awakeFromNib
{
    NSTableColumn* column = [[NSTableColumn alloc] initWithIdentifier:@"Hello"];
    [self addTableColumn:column];
    return;
}
When I run my project, I expect the LayoutView to have one column, with the header "Sunday". However, nothing appears at all. When I debug it through gdb, the command "p (int)[self numberOfColumns]" returns 1, so I know the column is there.

What am I missing? I haven't hooked LayoutView up to a data source yet. Is this necessary for the table to display at all, or am I missing something else?

Check out the Table View Programming Guide.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
I've inherited an iPhone app and I've got maybe 12 hours of experience in Xcode 4 and Objective C so I'm kind of stuck slamming my head against a wall for some issues I've encountered. The biggest problem I'm having is figuring out the best way to display the contents of an RSS or XML feed in a nice dynamic layout and have each item be clickable. I've found some example code online but half of them don't compile for whatever reason and there doesn't seem to be any quick any easy way to parse XML in Objective C. If anyone can point me in the right direction it'd be much appreciated. As a rundown of what I'm trying to do:
  • Ingest and parse an external web-based XML feed containing arbitrary data
  • Iterate through the results and print clickable text and images to a view
  • Onclick for each item call a function passing values on to a new page in the app (I've already got the function it would call written)
Once again thanks in advance for any advice. I didn't expect such a simple thing to stump me as much as it has but then again nothing I've encountered involving iOS development has been easy. :v:

OHIO
Aug 15, 2005

touchin' algebra

Yodzilla posted:

I've inherited an iPhone app and I've got maybe 12 hours of experience in Xcode 4 and Objective C so I'm kind of stuck slamming my head against a wall for some issues I've encountered. The biggest problem I'm having is figuring out the best way to display the contents of an RSS or XML feed in a nice dynamic layout and have each item be clickable. I've found some example code online but half of them don't compile for whatever reason and there doesn't seem to be any quick any easy way to parse XML in Objective C. If anyone can point me in the right direction it'd be much appreciated. As a rundown of what I'm trying to do:
  • Ingest and parse an external web-based XML feed containing arbitrary data
  • Iterate through the results and print clickable text and images to a view
  • Onclick for each item call a function passing values on to a new page in the app (I've already got the function it would call written)
Once again thanks in advance for any advice. I didn't expect such a simple thing to stump me as much as it has but then again nothing I've encountered involving iOS development has been easy. :v:

I use (and recommend) ASIHTTP for grabbing web stuff, and hpple for parsing (because you get XPath). But Google's objective-c XML parser is also great.

For your requirements it sounds like a Table View is a natural fit.

Also Ray has a tutorial related to your situation.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
Sweet, thanks for those resources. I'll take a gander tonight when I get back to my development environment.

LP0 ON FIRE
Jan 25, 2006

beep boop

rjmccall posted:

Is point a Superclass* with the child method only declared on a subclass? Because you need to cast down to the subclass to make that type-check.

I'm using Cocos2D, and I just found out it's apparently unavoidable, unless you edit the extensions in some way. Quoted from another forum, if this makes any sense "Cocos2d defines CGPointObject in CCParallaxNode.m, and although we're extending that class there's no handy way to let the compiler know about CGPointObject in our file."

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
You can still make a declaration for it with a category, but if the @interface and method are private to some implementation file then you're almost certainly not supposed to be accessing it.

stray
Jun 28, 2005

"It's a jet pack, Michael. What could possibly go wrong?"
I'm learning Xcode/Obj-C by writing an iOS app and I've got what I think is a pretty easy question. I've got a eleven-digit number (e.g., 12345678901) that I want to format as a phone number (e.g., 1 (234) 567-8901). How do I do that?

e: it's a number in a plist, not necessarily an NSNumber. Sorry.

stray fucked around with this message at 00:20 on Jun 22, 2011

LP0 ON FIRE
Jan 25, 2006

beep boop
There's a pretty cool blog post about how to format phone numbers and that are local aware here: http://the-lost-beauty.blogspot.com/2010/01/locale-sensitive-phone-number.html

Parentheses and dashes are not allowed in NSNumberFormatter, so I don't think that would help you.

LP0 ON FIRE fucked around with this message at 18:38 on Jun 21, 2011

ModeSix
Mar 14, 2009

ModeSix posted:

I have a question about scheduling updates.

I am using 2 scheduled updates, which will automatically unschedule and reschedule themselves based on a method within the scheduled function. I say this so you understand the schedules are fairly random.

I am trying to compare the time since last scheduled update ran.

ie: If schedule A has run within the last 0.5 seconds, delay schedule B by whatever amount of time it takes for it to be 0.6 seconds since schedule A ran.

I need to do this for both schedule A and B, which are both random.

Is there a way to check how long since a scheduled event ran?

Is there a way to add the necessary delay to a scheduled event based on the amount of time since another scheduled event ran?

Is there a way to check how long until the next scheduled event will run from the current point in time?

What I am doing here is spawning objects at 2 places, which move horizontally across the screen. I need there to be at least 0.6 seconds between items on opposite planes (top/bottom), in order to allow my player (sprite) to be able to fit into the space between the sprites. It is ok to spawn 2 items really close on the same plane, but opposite planes need some spacing.

Anyone?

I'm using cocos2d if that helps clarify the question.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



ModeSix posted:

Anyone?

I'm using cocos2d if that helps clarify the question.

It's been a long time since I've done any game code, but it seems like it would be less messy to have a single schedule/timer handle it.

Have it do "ticks" (for example every 0.1 second or whatever granularity you need) and keep a record of the last event that happened (for each event saving the "gametime" + the object spawned at that time). Then each tick, check the previous event(s), and see if there's any new actions to take, such as putting another object on the screen, what have you.

stray
Jun 28, 2005

"It's a jet pack, Michael. What could possibly go wrong?"

NOG posted:

There's a pretty cool blog post about how to format phone numbers and that are local aware here: http://the-lost-beauty.blogspot.com/2010/01/locale-sensitive-phone-number.html

Parentheses and dashes are not allowed in NSNumberFormatter, so I don't think that would help you.
Hm... that seems like drastic overkill. I don't need to create numbers you can dial from everywhere on Earth (yet); I just want to turn the number that I'm reading in from a plist into a nicely-formatted string that I can pump out to a UILabel. (I'm taking baby steps right now.)

I know there's something obvious I'm missing, here, but I can't even seem to get it to display right without the nice formatting. In trying to convert the number to a string, it's doing one of those horribly annoying format-conversion things. I thought %d would do it, but it doesn't. Aren't numbers in a plist just signed 32-bit integers?

ModeSix
Mar 14, 2009

Carthag posted:

It's been a long time since I've done any game code, but it seems like it would be less messy to have a single schedule/timer handle it.

Have it do "ticks" (for example every 0.1 second or whatever granularity you need) and keep a record of the last event that happened (for each event saving the "gametime" + the object spawned at that time). Then each tick, check the previous event(s), and see if there's any new actions to take, such as putting another object on the screen, what have you.

Hm, this might work if I can figure out how to implement it, shouldn't be too overly difficult, and it would still allow me to throw in a random seed every time something spawns.

Looks like I am going to have to rewrite a bunch of code, your way makes more sense and should help with overall readability of the code.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
OK I've got something really strange going on here and I have no idea what's up. Contained in the header file KCAViewController.h is this:

code:
@interface KCAViewController : UIViewController {
	BOOL shouldHideToolbar;
	
        ...
}

@property (readonly) BOOL shouldHideToolbar;
That bool shouldHideToolbar is a variable that pages which inherit this class can use to turn on or off a global toolbar in the application. That gets set like so:

code:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        ...

        shouldHideToolbar = YES;

	...
    }
    return self;
}
This works perfectly fine if I build the app with the target as an iPhone simulator and does exactly what I need it to do. However if I change the build target to iOS Device so I can Archive the app for testing it throws this error:

quote:

TriviaViewController.m:27: error: 'shouldHideToolbar' undeclared (first use in this function)

Why the hell would it compile and work when building with a device as a target but not when trying to archive it?

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe
What Xcode are you using, and where are you synthesizing your property? shouldHideToolbar = YES; is accessing the ivar directly, not the @property, for which you would need to do self.shouldHideToolbar = YES.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch

rjmccall posted:

What Xcode are you using, and where are you synthesizing your property? shouldHideToolbar = YES; is accessing the ivar directly, not the @property, for which you would need to do self.shouldHideToolbar = YES.

Awesome! Setting it to self.shouldHideToolbar fixed it along with removing the (readonly) attribute.

I'm using Xcode 4 but this app was built by another guy in Xcode 3. This begs the question of how or why doing things this way used to work and why it compiled for a device but not for archiving previously. I really don't get it.

Now I've got to figure out why these Urban Airship class files are throwing Apple Mach-O Linker Errors. Ugh...

e: nice, now i've learned all about adding frameworks kinda. hrmm

Yodzilla fucked around with this message at 05:48 on Jun 22, 2011

ModeSix
Mar 14, 2009

Carthag posted:

It's been a long time since I've done any game code, but it seems like it would be less messy to have a single schedule/timer handle it.

Have it do "ticks" (for example every 0.1 second or whatever granularity you need) and keep a record of the last event that happened (for each event saving the "gametime" + the object spawned at that time). Then each tick, check the previous event(s), and see if there's any new actions to take, such as putting another object on the screen, what have you.

Sometimes you can't see the forest for the trees, this is exactly what I needed to do.

Kudos.

I'll even let you see the abomination that I call the solution:
code:
-(void)spawnObstacles:(ccTime)delta
{
//    CCLOG(@"Spawning obstacles");

    // increment the interval since previous spawn
    lastCeilingMove += 0.1f;
    lastFloorMove += 0.1f;
    
    // check to see if ceiling has spawned recently and that we're not going 
    //to create an endless stream of spawned objects
    if (lastCeilingMove > 0.5f && numFloorSpawned < numCeilingSpawned + 1 && lastFloorMove > 0.5f)
    {
        //CCLOG(@"checking floor movement");
        int chanceToMoveFloor = arc4random() % 2;
            if (chanceToMoveFloor == 1)
            {
                CCLOG(@"Spawning floor object");
                int randomFloorObstacleIndex = CCRANDOM_0_1() * [floorObstacles count];
                CCSprite* floorObstacle = [floorObstacles objectAtIndex:randomFloorObstacleIndex];
                
                if ([floorObstacle numberOfRunningActions] == 0)
                {
                [self runFloorObstacleMove:floorObstacle];
                lastFloorMove = 0.0;
                numFloorSpawned += 1;                
                }
            }
    }
    
    // check to see if floor has spawned recently and that we're not going 
    //to create an endless stream of spawned objects
    if (lastFloorMove > 0.5f && numCeilingSpawned < numFloorSpawned + 1 && lastCeilingMove > 0.5f)
    {
        int chanceToMoveCeiling = arc4random() % 2;
            if (chanceToMoveCeiling == 1)
            {
                CCLOG(@"spawning ceiling object");
                int randomCeilingObstacleIndex = CCRANDOM_0_1() * [ceilingObstacles count];
                CCSprite* ceilingObstacle = [ceilingObstacles objectAtIndex:randomCeilingObstacleIndex];
                
                if ([ceilingObstacle numberOfRunningActions] == 0)
                {
                [self runCeilingObstacleMove:ceilingObstacle];
                lastCeilingMove = 0.0;
                numCeilingSpawned += 1;

                }
            }
    
    }

    // compensate for the increased movement speed when score is above 100; spawn objects more frequently
    if (score == 100)
    {
    
        CCLOG(@"rescheduling spawner");
        [self unschedule:@selector(spawnObstacles:)];
        [self schedule:@selector(spawnObstacles:) interval:0.08f];
        
    }

}
It works, I am going to have to tweak it some to make it a bit more random, but overall a working solution to my problem.

ModeSix fucked around with this message at 06:08 on Jun 22, 2011

Doc Block
Apr 15, 2003
Fun Shoe
Is it normal for the root view controller's viewDidLoad method to be called before the app delegate's application:didFinishLaunchingWithOptions: method?

dizzywhip
Dec 23, 2005

stray posted:

Hm... that seems like drastic overkill. I don't need to create numbers you can dial from everywhere on Earth (yet); I just want to turn the number that I'm reading in from a plist into a nicely-formatted string that I can pump out to a UILabel. (I'm taking baby steps right now.)

This should be pretty easy. Objective-C makes it quite a bit more cumbersome than other languages, but it's still fairly simple.

If you're certain you have a 10 digit integer, you can do something like this:

code:
NSString* phoneString = [NSString stringWithFormat: @"%d", phoneNumber];

NSString* formattedPhoneString = [NSString stringWithFormat: @"(%@) %@-%@", 
                                           [phoneString substringWithRange: NSMakeRange(0, 3)],
                                           [phoneString substringWithRange: NSMakeRange(3, 3)],
                                           [phoneString substringWithRange: NSMakeRange(6, 4)]];
Edit: Just noticed you have an 11 digit number, but the same concept applies.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Doc Block posted:

Is it normal for the root view controller's viewDidLoad method to be called before the app delegate's application:didFinishLaunchingWithOptions: method?

That sounds abnormal but not impossible, especially if the root view controller is in your main nib file. Do you have a problem triggered by the ordering of the calls, or are you just curious?

Doc Block
Apr 15, 2003
Fun Shoe

pokeyman posted:

That sounds abnormal but not impossible, especially if the root view controller is in your main nib file. Do you have a problem triggered by the ordering of the calls, or are you just curious?

Yeah, my app delegate is supposed to restore the app's state on startup, but since the root view is somehow getting loaded first, it will always act as if this is the first time the user has run the app.

It's a universal app, started from the Window template, and I think the problem is just how I connected everything up. The root view controller is in a separate nib.

edit: aaand it's fixed. :ughh: Ask for help and immediately get it working yourself.
I think the overall gist of it was that I had connected the root view controller to the main window's rootViewController property in Interface Builder (or whatever it's called now in Xcode 4) instead of doing it in code in the app delegate's application:didFinishLaunchingWithOptions: method. And when MainWindow.xib was loading, my root view controller would get loaded too because of the connection made in IB.

Doc Block fucked around with this message at 09:10 on Jun 22, 2011

stray
Jun 28, 2005

"It's a jet pack, Michael. What could possibly go wrong?"

Gordon Cole posted:

This should be pretty easy. Objective-C makes it quite a bit more cumbersome than other languages, but it's still fairly simple.

If you're certain you have a 10 digit integer, you can do something like this:

code:
NSString* phoneString = [NSString stringWithFormat: @"%d", phoneNumber];

NSString* formattedPhoneString = [NSString stringWithFormat: @"(%@) %@-%@", 
                                           [phoneString substringWithRange: NSMakeRange(0, 3)],
                                           [phoneString substringWithRange: NSMakeRange(3, 3)],
                                           [phoneString substringWithRange: NSMakeRange(6, 4)]];
Edit: Just noticed you have an 11 digit number, but the same concept applies.
Oh, I see. I wasn't sure about %@, whether you could have more than one in there. Thanks!

AlwaysWetID34
Mar 8, 2003
*shrug*
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

AlwaysWetID34 fucked around with this message at 17:29 on Jan 18, 2019

Small White Dragon
Nov 23, 2007

No relation.
WWDC 2011 videos are up.

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.

Mikey-San
Nov 3, 2005

I'm Edith Head!

lord funk posted:

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

Tell her these are Keynote presentations. Totally better.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Small White Dragon posted:

WWDC 2011 videos are up.

And just so we're all clear, all you need is the free developer account to watch the videos. So do it.

wolffenstein
Aug 2, 2002
 
Pork Pro
Does this mean the WWDC NDA is gone?

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
So I'm trying to implement push notifications using Urban Airship in an app and I'm absolutely confounded by these errors. I had this poo poo working last night and it compiles if my target is iOS Device but if I try to compile it to run in a simulator I get over a hundred Apple Mach-O Linke Errors like this:

quote:

Undefined symbols for architecture i386:
"_SCNetworkReachabilitySetCallback", referenced from:
-[Reachability startNotifier] in Reachability.o
-[UA_Reachability startNotifier] in libUAirship-1.0.5.a(UA_Reachability.o)

"_kCFStreamPropertyHTTPProxyHost", referenced from:
-[UA_ASIHTTPRequest startRequest] in libUAirship-1.0.5.a(UA_ASIHTTPRequest.o)

And I just don't get it. I've included all of the frameworks that the UA sample app was using and I can't find any documentation on what those errors even mean.

e: it's doubly confusing because it refuses to compile and run in the simulator but i can install it to my iPad and it works just fine. i really don't get it

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Yodzilla posted:

So I'm trying to implement push notifications using Urban Airship in an app and I'm absolutely confounded by these errors. I had this poo poo working last night and it compiles if my target is iOS Device but if I try to compile it to run in a simulator I get over a hundred Apple Mach-O Linke Errors like this:


And I just don't get it. I've included all of the frameworks that the UA sample app was using and I can't find any documentation on what those errors even mean.

e: it's doubly confusing because it refuses to compile and run in the simulator but i can install it to my iPad and it works just fine. i really don't get it

It looks like the library doesn't even contain code for the simulator (i386).

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
Which is weird because they explicitly say on their site that they new 1.0.5 version does contain the library. And whatever version of Urban Airship that Appcelerator uses works just fine in the simulator so I really don't know.

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Yodzilla posted:

Which is weird because they explicitly say on their site that they new 1.0.5 version does contain the library. And whatever version of Urban Airship that Appcelerator uses works just fine in the simulator so I really don't know.

Check this page out:

http://support.urbanairship.com/customer/portal/questions/3170-push-api-libuairship-1-4-a-missing-required-architecture-i386

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
Yeah that's the page where they poster is using 1.0.4 and UA says that i368 support is coming in 1.0.5. I'm currently using the latest version which is v1.0.5a so either something else is wrong or Urban Airship lied.

Yodzilla
Apr 29, 2005

Now who looks even dumber?

Beef Witch
So I removed all of my included frameworks and re-added them all again and it mysteriously works now.


gently caress everything.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

wolffenstein posted:

Does this mean the WWDC NDA is gone?

As far as I know it's replaced with the Developer NDA, so you still can't talk about session contents on a forum such as this one.

The rule of thumb I use: if I don't need to log in to see Apple's page/docs about it, I can probably talk about it. IANAL etc. but that's my thinking.

Carthag Tuek
Oct 15, 2005

Tider skal komme,
tider skal henrulle,
slægt skal følge slægters gang



I guess that's why it's hard to find much discussion about the things by googling around. Lot of them are really cool and I'd love to see what others think of them.

Adbot
ADBOT LOVES YOU

fankey
Aug 31, 2001

I'm displaying a UIPickerView dynamically based on a button press and want to select an item in the picker. If the orientation of the iPhone is portrait then calling [UIPickerView selectRow] works fine with animated being YES or NO. If the orientation is landscape, selectRow only works if I set animated to NO. If I attempt to animate the selection it fails and leaves the first item selected.

I'm attempting to select the item in viewDidLoad - is there a better place to do this? Here's my controller code in case it helps.

code:
#import "pickController.h"

@implementation pickController
@synthesize picker;

- (void)viewDidLoad 
{
  [super viewDidLoad];
  [picker selectRow:2 inComponent:0 animated:YES];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
  return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView 
numberOfRowsInComponent:(NSInteger)component
{
  return 4;
}

- (void)pickerView:(UIPickerView *)pickerView 
      didSelectRow:(NSInteger)row 
       inComponent:(NSInteger)component
{
}

- (NSString *)pickerView:(UIPickerView *)pickerView 
             titleForRow:(NSInteger)row 
            forComponent:(NSInteger)component
{
  return [NSString stringWithFormat:@"Item %i", row];
}

- (CGFloat)pickerView:(UIPickerView *)pickerView 
    widthForComponent:(NSInteger)component
{
  return 200;
}

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
  return YES;
}


- (void)didReceiveMemoryWarning 
{
  [super didReceiveMemoryWarning];
}

- (void)viewDidUnload 
{
  self.picker = nil;
  [super viewDidUnload];
}

@end

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