
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
- 118 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
-
- 48058
- 0
- Ago 31, 2017
Otras Preguntas y Respuestas
- entre Desarrolladores (Desarrolladores)
Respuestas WordPress (Usuarios WordPress)
Preguntas sin respuesta
-
- 155
- 0
- Ago 4, 2022
-
- 164
- 0
- Feb 25, 2022
-
- 226
- 1
- Ene 1, 2022
-
- 609
- 0
- Nov 24, 2021
-
- 1193
- 1
- Sep 12, 2021
-
- 394
- 0
- Jul 6, 2021
-
- 481
- 0
- Mar 27, 2021
-
- 385
- 1
- Feb 2, 2021
- ver todas las preguntas
Actividad Reciente
mozzer respondió hace 5 días
Calibración de bateríamozzer respondió Mar 10
Calibración de bateríaPeter respondió Mar 10
Calibración de bateríamozzer preguntó Mar 10
Calibración de bateríaPeter comentó Nov 5, 2022
Imposible importar Fotos + problema con Musica
Ultimas Respuestas
Peter respondió
Ejecuta algún proceso para que se termine la bate
1Peter respondió
¿Los dos teléfonos tienen el mismo Apple ID y co
1DaleGarrote respondió
Se solucionó con las actualización a iOS 16 App
1Peter respondió
Si abre el archivo correctamente, cuando esté abi
0Peter respondió
Cada cuenta es independiente si se utiliza de form
1Peter respondió
Será lo que tarda el proceso en sincronizar todos
1Peter respondió
El problema debe de ser que tienes una versión vi
0Ultimos Comentarios
DJUNQUERA comentó
...