2009-08-30 11 views
1

J'ai un UISegmentedControl et chaque fois que je touche un bouton il devrait afficher une alerte à l'indice du segment sélectionné:selectedSegmentIndex fait mon accident d'application

- (IBAction)bOkayTouched:(id)sender 
{ 
    NSString *msg = [NSString stringWithFormat:@"%@", [scRPSSL selectedSegmentIndex]]; 
    UIAlertView *lol = [[UIAlertView alloc] initWithTitle:@"Mkay" message:msg delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil]; 
    [lol show]; 
    [lol release]; 
} 

Cependant, les application se bloque quand il doit créer le NSString . Mais il ne plante pas lorsque je remplace cette ligne par:

NSString *msg = [NSString stringWithFormat:@"XD"]; 

ou similaire.

Oh, et voici ce que le débogueur me dit:

[Session started at 2009-08-30 21:04:38 +0200.] 

[Session started at 2009-08-30 21:04:43 +0200.] 
GNU gdb 6.3.50-20050815 (Apple version gdb-966) (Tue Mar 10 02:43:13 UTC 2009) 
Copyright 2004 Free Software Foundation, Inc. 
GDB is free software, covered by the GNU General Public License, and you are 
welcome to change it and/or distribute copies of it under certain conditions. 
Type "show copying" to see the conditions. 
There is absolutely no warranty for GDB. Type "show warranty" for details. 
This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all 
Attaching to process 4630. 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
unable to read unknown load command 0x80000022 
(gdb) 

Quelqu'un peut-il me aider? En outre, l'alerte indique '(null)' si l'index sélectionné est 0 (zéro).

Merci!

+0

vous pouvez également faire '[expéditeur selectedSegmentIndex]', puisque le argument 'sender' est le contrôle qui a envoyé l'action – newacct

+0

Mais le bouton a envoyé l'action: P –

Répondre

4

selectedSegmentIndex est probablement une valeur entière, auquel cas la chaîne de format %@ n'est pas le bon choix. Essayez ce qui suit à la place:

[NSString stringWithFormat:@"%d", [scRPSSL selectedSegmentIndex]]; 

Plus d'informations peuvent être trouvées dans la documentation des développeurs d'Apple sur format specifiers, mais l'essentiel de ce que %@ est utilisé uniquement pour les sous-classes de NSObject. Cela fonctionne en appelant [object description] qui renvoie une chaîne. Si vous l'utilisez sur une valeur entière, vous envoyez essentiellement un message Objective-C à quelque chose qui n'est pas un objet, ce qui entraîne un comportement indéfini (en général un crash).

+0

ZOMFG que l'homme travaille thanx –

+0

Je ne peux pas upvote dès maintenant cuz J'ai déjà atteint la limite de vote. Je vais voter dans 4 heures. –

+0

Heureux d'aider :) –

Questions connexes