2009-08-14 8 views
0

Je suis nouveau à Objective-C et j'ai besoin d'aide!UIPageControl avec UIView avec le bouton

Je suis l'exemple "PageControl" qui peut être trouvé sur le net. J'ai ajouté un bouton à la vue dans la NIB et ai accroché une action dont l'implémentation est trouvée ci-dessous.

Voici ma définition du contrôleur de vue affiché dans le contrôle de la page:

 
//ContactCardViewController.h 
@interface ContactCardViewController : UIViewController 
{ 
    int pageNumber; 
    NSMutableString *s; 
} 


//ContactCardViewController.m implementation 

- (id)initWithPageNumber:(int)page { 
    if (self = [super initWithNibName:@"ContactCardViewController" bundle:nil]) { 
     s = [[NSString alloc] initWithFormat:@"page: %d", page];    
    } 
    return self; 
} 


- (id)initWithString:(NSDictionary *)_s { 
    if (self = [super initWithNibName:@"ContactCardViewController" bundle:nil]) { 
     NSMutableString *t = [[NSMutableString alloc] initWithString:_s]; 
     s = t; 
    } 
    return self; 
} 


-(IBAction)callOrAddToContacts:(id)sender 
{ 
    jobtitleLabel.text = s; 
} 


//AppDelegate.m 
//in delegate that loads the scroll view with the view for the current page: 

- (void)loadScrollViewWithPage:(int)page { 
//init the view this way the page: and the correct page number is displayed 
    controller = [[ContactCardViewController alloc] initWithPageNumber:page ]; 

//init the view this way, the value of the first person is always displayed 
    controller = [[ContactCardViewController alloc] initWithString:[[self.allNames objectAtIndex:page] objectForKey:@"firstname"]]; 

} 


S'il vous plaît aidez-moi à comprendre pourquoi lorsque la vue est créé avec initWithString et accessible via l'action du bouton uniquement de la valeur pour la La première personne de la liste est toujours renvoyée. Lorsque i init la vue utilisant initWithPageNumber s a la valeur correcte Page: X.

Répondre

0

Dans le code InitWithString, vous transmettez un dictionnaire et non une chaîne.

- (id)initWithString:(NSDictionary *)_s { 
    if (self = [super initWithNibName:@"ContactCardViewController" bundle:nil]) { 
     NSMutableString *t = [[NSMutableString alloc] initWithString:_s]; 
     s = t; 
    } 
    return self; 
}

Vous pouvez changer cela à NSString, ou changer le NSMutableString ... à une instance de NSDictionary. Un ou l'autre.

+0

Merci beaucoup! copier/coller l'erreur. Avec

 - (id)initWithString:(NSMutableString *)_s { 
Le même problème existe. code dans l'action lorsque vous essayez de lire s lit toujours la première valeur dans la liste indépendamment de la page sur laquelle le contrôle est actuellement – radiofrequency

0

Trouvé le problème était dans le fichier plist. Le code est bien.

Questions connexes