Actualiser la vue de la table?

Je pense que j'ai plutôt une tâche facile, mais de toute façon, il ne veut pas travailler. Je suis un débutant total en objective-c, donc je suppose que c'est juste une petite erreur. Je ne sais vraiment pas ce que je fais, actuellement il est plus comme la copie&pâte de programmation. Comme je ne sais pas vraiment si j'ai besoin de la IBOutlet dans l'interface ou comme une propriété ou les deux.

Ce que j'ai:

Un ViewController avec un Bouton, une Étiquette et une Vue de la Table. Le bouton se connecte à un sharepoints serveur et lit une liste et ajoute de la valeur à un tableau. Cette partie fonctionne.

Délégué et de la source de données de sortie est connecté à la Vue-Contrôleur.

Ce que je veux:

Le tableau doit être la source de données de la Vue de la Table, donc j'ai juste envie de se rafraîchir après j'ai lu les nouvelles données dans le tableau. Les données de test j'ai ajouter dans le viewDidLoad fonction de la matrice de, se montre. Donc je suppose que j'ai en quelque sorte connecté le tableau à la vue de la table.

Je vais vous donner le code complet:

ViewController.h:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
    IBOutlet UILabel *output;
    IBOutlet UITableView *tableView;
    NSMutableData *webData;
    NSString *finaldata;
    NSString *convertToStringData;
    NSMutableString *nodeContent;
}
@property (nonatomic, retain) UILabel *output;
@property (nonatomic, weak) IBOutlet UITableView *tableView;
-(IBAction)invokeService:(UIButton *) sender;

@end

ViewController.m:

#import "ViewController.h"
@interface ViewController ()
{
NSMutableArray *foundUrlaub;
}
@end
@implementation ViewController
@synthesize output;
- (void)viewDidLoad
{
[super viewDidLoad];
//SOME TEST DATA... THIS SHOWS UP IN MY TABLE VIEW
foundUrlaub = [[NSMutableArray alloc]init];
[foundUrlaub addObject:@"first cell"];
[foundUrlaub addObject:@"second cell"];
[foundUrlaub addObject:@"third cell"];
}
-(IBAction)invokeService:(UIButton *) sender
{
//connection to sharepoint
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"didReceiveResponse");
[webData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(@"didReceiveData");
[webData appendData:data];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"ERROR with the Connection");
NSLog(error.description);
}
-(BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
{
NSLog(@"canAuthenticateAgainstProtectionSpace");
return YES;
}
-(void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
NSLog(@"didReceiveAuthenticationChallenge");
NSURLCredential *credential = [NSURLCredential credentialWithUser:@"XXXXXX" password:@"XXXXXX" persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"DONE. Received Bytes: %d", [webData length]);
convertToStringData = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"(?<=ows_Title=')(.*)(?=' ows_MetaInfo)" options:0 error:NULL];
NSArray *matches = [regex matchesInString:convertToStringData options:0 range:NSMakeRange(0, [convertToStringData length])];
//HERE I LOAD SOME DATA IN THE ARRAY
[foundUrlaub removeAllObjects];
for (NSTextCheckingResult *match in matches)
{
NSRange matchRange = [match rangeAtIndex:1];
NSString *matchString = [convertToStringData substringWithRange:matchRange];
NSLog(@"Match: %@", matchString);
[foundUrlaub addObject:matchString]; //<- ADDS 3 STRINGS TO ARRAY
}
//THIS DOES NOT WORK!
[tableView reloadData];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
//Dispose of any resources that can be recreated.
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [foundUrlaub count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"TableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [foundUrlaub objectAtIndex:indexPath.row];
return cell;
}
@end
Pas un Xcode question.
vous obtenez des données à partir du serveur à l'aide de NSURLConnection asynchrone afin qu'il utilise des threads séparés pour l'envoi et la réception de données.
essayez de faire comme je l'ai dit et voir si sa fonctionne ou pas?
r u obtenir des données en foundUrlaub avoir u imprimé.
tble vue montrant trois lignes en ce moment qui est des valeurs statiques?

OriginalL'auteur Feroc | 2013-07-22