Je dois prendre cette structure de données, un nsmutablearray, et parcourir chaque index et imprimer chaque champ dans un champ de texte. chaque bouton "en avant" incrémente les données avant et "en arrière" remonte. J'ai vraiment du mal à faire fonctionner cela correctement, est-ce que quelqu'un sait ce que je fais mal. Gardez à l'esprit, l'objet tenu dans le tableau, appelé info_holder, est un objet qui contient 3 chaînes et un compteur:Iterate through NS array of obs
#import "ZDViewController.h"
@implementation ZDViewController
@synthesize password;
@synthesize count;
@synthesize web;
@synthesize username;
@synthesize header;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *array = [[NSMutableArray alloc] init];
info_holder *set1 = [[info_holder alloc] init];
info_holder *set2 = [[info_holder alloc] init];
info_holder *set3 = [[info_holder alloc] init];
info_holder *set4 = [[info_holder alloc] init];
info_holder *set5 = [[info_holder alloc] init];
[set1 SetUser: @"info1"]; //temporary information until big is fixed
[set1 SetPass: @"info2"];
[set1 SetKey: @"webinfo1"];
[set1 SetCount: 0];
[set2 SetUser: @"info3"];
[set2 SetPass: @"info4"];
[set2 SetKey: @"webinfo2"];
[set2 SetCount: 0];
[set3 SetUser: @"info5"];
[set3 SetPass: @"info6"];
[set3 SetKey: @"webinfo3"];
[set3 SetCount: 0];
[set4 SetUser: @"info7"];
[set4 SetPass: @"info8"];
[set4 SetKey: @"webinfo4"];
[set4 SetCount: 0];
[set5 SetUser: @"info9"];
[set5 SetPass: @"info10"];
[set5 SetKey: @"Webinfo5"];
[set5 SetCount: 0];
}
- (void)viewDidUnload
{
[self setHeader:nil];
[self setWeb:nil];
[self setPassword:nil];
[self setCount:nil];
[self setUsername:nil];
[super viewDidUnload];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)increment:(id)sender {
if([email protected]"test")
[email protected]"test2";
else
[email protected]"test";
//this should print a new username NSSTRING, wedsite NSTRING, password NSTRING and INEGER counter, heald in the info_holder object, incremented per click backwards
}
- (IBAction)decrement:(id)sender {
}
- (IBAction)Inc:(id)sender {
}
- (IBAction)textFieldDoneEditing:(id)sender {
[sender resignFirstResponder];
}
- (IBAction)backgroundTap:(id)sender {
[web resignFirstResponder];
[username resignFirstResponder];
[count resignFirstResponder];
[password resignFirstResponder];
}
@end
et ma principale est:
#import <UIKit/UIKit.h>
#import "ZDAppDelegate.h"
#import "info_holder.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([ZDAppDelegate class]));
}
}
Vous n'avez jamais, jamais besoin de changer votre main.m du tout. –