
Conecta
Nido Apple
Recibe ayuda de expertos
Registrate y pregunta
Es gratis y fácil
Recibe respuestas
Respuestas, votos y comentarios
Vota y selecciona respuestas
Recibe puntos, vota y da la solución
Pregunta
Problema imagen en una View (xml Parsing)
- preguntó
- Desarrolladores Apple
- 156 Vistas
- 2 Respuestas
- abierta
Hola a todos,
tengo un problema en este proyecto,
en el primer Viewcontroller tengo tre Label i un imagen, esta información esta generada por un file xml,
la primera View se ve todo, imagen pequeña y las tres Label pero quando paso alla view sucesiva me da un error en la imagen,
la unica manera para ver el proyecto es comentar // este código que me da el error,
así puedo ver el proyecto pero el problema es que en la segunda view naturalmente no se ve la imagen.
este es el código che me da error puede ser che me estoy olvidando algo?
[PHP]imgSong.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURLURLWithString:[self.dictionaryObject valueForKey:@"thumb_url"]]]];[/PHP]
El "thumb_url" en la celda se ve pero no en la segunda View no.
Gracias a todos por un ayuda.


2 Respuestas
Primero tienes que llamar tu xml... yo nunca he usado XML pero pienso que puedes hacer lo mismo que con php ósea formato JSON
primero creas un archivo donde recibas los datos... ejemplo:
[PHP]//recibirData.h
#import
@protocol RecibirDatosProtocol
- (void)itemsDownloaded:(NSArray *)items;
@end
@interface recibirData : NSObject
@property (nonatomic, weak) id delegate;
- (void)downloadItems;
@end
///////////////////////////////////////////////////////////////////
//recibirData.m
#import "HomeModel2.h"
#import "Location2.h"
@interface recibirData()
{
NSMutableData *_downloadedData;
}
@end
@implementation recibirData
- (void)downloadItems
{
// Download the json file
NSURL *jsonFileUrl = [NSURLURLWithString:[NSStringstringWithFormat:mad:""]];
// Create the request
NSURLRequest *urlRequest = [[NSURLRequestalloc] initWithURL:jsonFileUrl];
// Create the NSURLConnection
[NSURLConnectionconnectionWithRequest:urlRequest delegate:self];
}
#pragma mark NSURLConnectionDataProtocol Methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
// Initialize the data object
_downloadedData = [[NSMutableDataalloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// Append the newly downloaded data
[_downloadedDataappendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
// Create an array to store the locations
NSMutableArray *_locations = [[NSMutableArrayalloc] init];
// Parse the JSON that came in
NSError *error;
NSArray *jsonArray = [NSJSONSerializationJSONObjectWithData:_downloadedDataoptions:NSJSONReadingAllowFragmentserror:&error];
for (int i = 0; i < jsonArray.count; i++)
{
NSDictionary *jsonElement = jsonArray;
// Create a new location object and set its props to JsonElement properties
Location2 *newLocation = [[Location alloc] init];
newLocation.xxxxxx = jsonElement[@"xxxxxx"];
// Add this question to the locations array
[_locations addObject:newLocation];
}
}
if (self.delegate)
{
[self.delegate itemsDownloaded:_locations];
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
Con eso ya inicias otra clase con los Strins que usaras... lo lo he llamado Location
///////////////////////////////////////////////////////////////////////////////////////////////////
//Location.h
#import
@interface Location : NSObject
@property (nonatomic, strong) NSString *xxxxxx;
@end
//////////////////////////////////////////////////////////////////////////////////////////////////
//Location.m
#import "Location.h"
@implementation Location2
@end
///////////////////////////////////////////////////////////////////////////////////////////////////
lo siguiente es que en tu clase de tableView llamaras a esos datos... y después tienes que configurar un Segue donde pase los datos de la Cell a el DetailView.
////////////////////////////////////////////////////////////////////////////////////////////////////
//TableView.h
#import
#import "recibirData.h"
@interface InvitadosViewViewController : UIViewController
@property (weak, nonatomic) IBOutletUITableView *listTableView;
@end
////////////////////////////////////////////////////////////////////////////////////////////////////
//TableView.m
#import "TableView.h"
#import "Location.h"
#import "DetailViewController.h"
@interface TableView()
{
recibirData *_recibirData;
NSArray *_feedItems;
Location *_selectedLocation;
}
@end
@implementation TableView
- (void)viewDidLoad
{
[superviewDidLoad];
// Set this view controller object as the delegate and data source for the table view
self.listTableView.delegate = self;
self.listTableView.dataSource = self;
// Create array object and assign it to _feedItems variable
_feedItems = [[NSArrayalloc] init];
_recibirData = [[recibirDataalloc] init];
// Set this view controller object as the delegate for the home model object
_recibirData.delegate = self;
// Call the download items method of the home model object
[_recibirDatadownloadItems];
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)itemsDownloaded:(NSArray *)items
{
// This delegate method will get called when the items are finished downloading
// Set the downloaded items to the array
_feedItems = items;
// Reload the table view
[self.listTableViewreloadData];
}
#pragma mark Table View Delegate Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of feed items (initially 0)
return_feedItems.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
[UIApplicationsharedApplication].networkActivityIndicatorVisible = NO;
// Retrieve cell
NSString *cellIdentifier = @"BasicCell";
UITableViewCell *myCell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(myCell == nil) {
myCell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:cellIdentifier];
}
// Get the location to be shown
Location *item = _feedItems[indexPath.row];
// Get references to labels of cell
return myCell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Set selected location to var
_selectedLocation = _feedItems[indexPath.row];
// Manually call segue to detail view controller
[selfperformSegueWithIdentifier:mad:"detailSegue"sender:self];
}
#pragma mark Segue
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:mad:"detailSegue"]){
//Get reference to the destination view controller
DetailViewController *detailVC = segue.destinationViewController;
// Set the property to the selected location so when the view for
// detail view controller loads, it can access that property to get the feeditem obj
detailVC.selectedLocation = _selectedLocation;
}else{
}
}
@end
////////////////////////////////////////////////////////////////////////////////////////////////////[/PHP]
ya en tu DetailView jalas los datos con self.selectedLocation y listo
Por favor, accede o regístrate para añadir un comentario.
Gracias por tu respuesta muy gentil,
el error eta aqui
NSURLURLWithString (ERROR)
NSURL URLWithString (GUSTO)
El NSURL estaba todo pegado al URL por eso que no podia ver la imagen y me venia el error
Ahora todo bien!
Gracias
Por favor, accede o regístrate para añadir un comentario.
Por favor, accede o regístrate para responder a esta pregunta.
En el blog
-
- 49711
- 1
- Ago 31, 2017
Otras Preguntas y Respuestas
- entre Desarrolladores (Desarrolladores)
Respuestas WordPress (Usuarios WordPress)
Sin Respuesta
-
- 29
- 0
- hace 5 días
-
- 669
- 0
- Oct 2
-
- 372
- 0
- Jul 7
-
- 534
- 0
- Ago 4, 2022
-
- 545
- 0
- Feb 25, 2022
-
- 666
- 1
- Ene 1, 2022
-
- 1001
- 0
- Nov 24, 2021
-
- 1766
- 1
- Sep 12, 2021
- ver todas
Actividad Reciente
noiseapp preguntó hace 5 días
AirPods desbalanceadosDaleGarrote preguntó Oct 2
MacBookPro con Wifi dañadaDaleGarrote seleccionó una respuesta Sep 30
Sonoma no conecta a internetPeter respondió Sep 29
Mac OS X Versión 10.4.11. Como puedo activar el ve…Peter comentó Sep 29
icloud recordatorios no se pueden compartir - el p…
Ultimas Respuestas
Peter respondió
No es posible, pero si pones a codificar algún vi
0DaleGarrote respondió
EUREKA!!! Tenia instalado el Little Snitch, que no
1Peter respondió
Haz lo mismo pero en estos pasos. 1- Apaga la Mac
1Peter respondió
Contacta con la persona que te comparte las cosas,
0alex_ respondió
hola bueno te comento si el ssd que compraste es c
0alex_ respondió
hola peter y una pregunta fíjate que he visto var
0Peter respondió
Seguramente sea por causa de la memoria RAM. 8 GB
1Ultimos Comentarios
...