- Registriert
- 24.02.11
- Beiträge
- 14
Hallo Leute,
folgendes Problem diesmal, ich bekomme folgendes nicht hin:
Ich parse ne XML und füge ne Subview hinzu welche ein CustomImagePickerController ist. Das funktioniert auch. nur möchte ich die Zeit des Wartens auf die Bilder (Es müssen ja alle Bilder geladen werden bis der PickerController angezeigt wird) mit einem Activityindicator überbrücken.
Genau das bringe ich nicht hin.
Habe durch Google und im Forum leider nichts hilfreiches gefunden.
Kann mir da bitte jemand helfen?
hier noch mein Code:
Liebe Grüße und Danke schon mal im Voraus
folgendes Problem diesmal, ich bekomme folgendes nicht hin:
Ich parse ne XML und füge ne Subview hinzu welche ein CustomImagePickerController ist. Das funktioniert auch. nur möchte ich die Zeit des Wartens auf die Bilder (Es müssen ja alle Bilder geladen werden bis der PickerController angezeigt wird) mit einem Activityindicator überbrücken.
Genau das bringe ich nicht hin.
Habe durch Google und im Forum leider nichts hilfreiches gefunden.
Kann mir da bitte jemand helfen?
hier noch mein Code:
Code:
#import "PicViewController.h"
#import "PicGalleryViewController.h"
#import "PicSlideGalleryController.h"
@implementation PicGalleryViewController
@synthesize selectGal;
@synthesize selectGalTitle;
@synthesize currentElement, currentImg;
@synthesize galParser;
@synthesize Images;
@synthesize img;
-(void)viewDidLoad{
[super viewDidLoad];
UIActivityIndicatorView *activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease];
//[[self view] addSubview: activityView];
activityView.center = CGPointMake(240,160);
if([Images count]==0){
NSString * path = [NSString stringWithFormat:@"http://www.xxx.de/ex/gp%@.xml",selectGal];
[self parseXMLFileAtURL:path];
[[self view] addSubview: activityView];
[activityView startAnimating];
}
self.navigationItem.title = selectGalTitle;
self.view.backgroundColor = [[[UIColor alloc] initWithPatternImage: [UIImage imageNamed:@"cream_bg02.png"]]autorelease];
UIScrollView *GalleryView = [[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 360)]autorelease];
int row = 0;
int column = 0;
for(int i = 0; i < Images.count; ++i) {
NSString *thumb = [[Images objectAtIndex:i ]objectForKey:@"img"];
NSString *path = [NSString stringWithFormat:@"http://www.xxx.de/GALLERY/%@/IThumbs",selectGal];
NSString *thumbUrl = [NSString stringWithFormat:@"%@/%@",path,thumb];
NSData *imageData = [[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:thumbUrl]]autorelease];
UIImage *eImg = [[[UIImage alloc]initWithData:imageData]autorelease];
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(column*100+10, row*100+10, 98,98);
[button setImage:eImg forState:UIControlStateNormal];
[button addTarget:self
action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
[GalleryView addSubview:button];
if (column == 2) {
column = 0;
row++;
} else {
column++;
}
}
[GalleryView setContentSize:CGSizeMake(320, (row+2) * 98 + 10)];
[[self view] addSubview:GalleryView];
}
- (void)parseXMLFileAtURL:(NSString *)URL{
Images = [[NSMutableArray alloc] init];
NSURL *xmlURL = [NSURL URLWithString:URL];
galParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[galParser setDelegate:self];
[galParser setShouldProcessNamespaces:NO];
[galParser setShouldReportNamespacePrefixes:NO];
[galParser setShouldResolveExternalEntities:NO];
[galParser parse];
[galParser release];
}
- (void)parser:(NSXMLParser *)parser parseErrorOccured:(NSError *)parseError{
NSString *errorString = [NSString stringWithFormat:@"Keine Videos verfügbar(ErrorCode %i)",[parseError code]];
NSLog(@"Error parsing XML:%@", errorString);
UIAlertView * errorAlert = [[UIAlertView alloc]initWithTitle:@"Error loading content" message:errorString delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[errorAlert show];
[errorAlert release];
}
- (void)parserDidStartDocument:(NSXMLParser *)parser{
NSLog(@"Starte Parsing");
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:
(NSString *)qName attributes:(NSDictionary *)attributeDict{
currentElement = [elementName copy];
if ([elementName isEqualToString:@"galimg"]){
img =[[NSMutableDictionary alloc]init];
currentImg = [[NSMutableString alloc]init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if ([currentElement isEqualToString:@"gimg"]){
[currentImg appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:@"galimg"]){
[img setObject:currentImg forKey:@"img"];
[Images addObject:[img copy]];
NSLog(@"Hinzufügen eines Bildes %@",currentImg);
[img release];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser{
NSLog(@"Parsen beendet");
NSLog(@"Anzahl eingelesener Elemente: %d", [Images count]);
}
-(void)buttonClicked:(id)sender{
UIButton *button = (UIButton*)sender;
NSString *sImage = [[Images objectAtIndex:button.tag]objectForKey:@"img"];
NSString *selectedGalID = selectGal;
PicSlideGalleryController *PSGController = [[[PicSlideGalleryController alloc] initWithNibName:@"PicSlideGalleryController" bundle:[NSBundle mainBundle]]autorelease];
//PSGController.Images = Images;
PSGController.sImage = sImage;
PSGController.selectedGalID = selectedGalID;
[self.navigationController pushViewController:PSGController animated:YES];
PSGController = nil;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
- (void)dealloc {
[currentImg release];
[Images release];
[super dealloc];
}
@end
Liebe Grüße und Danke schon mal im Voraus