In one.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
NSString *carNumber = [self.carNumberArrayFromPlistFile objectAtIndex:row];
NSString *engineNumber = [self.engineNumberArrayFromPlistFile objectAtIndex:row];
CarInfo *oneCarInfo = [[CarInfo alloc] initWithCarNumber:carNumber engineNumber:engineNumber];
Two *two = [[Two alloc] initWithNibName:#"Two" bundle:nil];
two.car = oneCarInfo;
[self.navigationController pushViewController:two animated:YES];
[oneCarInfo release];
[two release];
}
In two.h
#interface Two : UITabBarController
{
CarInfo *car;
}
#property (nonatomic, retain)CarInfo *car;
And why the car in Two.m is always null? Please help me with this. Thank you guys!
Two.m:
#interface Two ()
#end
#implementation Two
#synthesize car;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.car = nil;
}
- (void)dealloc
{
[super dealloc];
}
#end
#PeterPajchl : you are not supposed to push instance of UITabBarController onto the stack of UINavigationController - check the documentation.
Related
#import "sideTableViewController.h"
#interface sideTableViewController ()
{
NSArray *colours;
}
#end
#implementation sideTableViewController
#synthesize colorNames;
#synthesize sideTableView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.sideTableView.delegate= self;
self.sideTableView.dataSource=self;
colorNames = [NSArray arrayWithObjects:#"Archie",#"Sethi",#"Rajan" ,#"Deepak" ,nil];
}
- (NSInteger)sideTableView:(UITableView *)sideTableView numberOfRowsInSection:(NSInteger)section
{
return [colorNames count];
}
- (UITableViewCell *)sideTableView:(UITableView *)sideTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
cell = [sideTableView dequeueReusableCellWithIdentifier:#"MyCell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"MyCell"];
}
cell.textLabel.text =[colorNames objectAtIndex:indexPath.row];
// NSLog(#"the indexpath is %#",indexPath);
return cell;
}
- (void)sideTableView:(UITableView *)sideTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [sideTableView cellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[sideTableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
and this is the header file...
#import <UIKit/UIKit.h>
#interface sideTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
NSArray *colorNames;
}
#property (strong, nonatomic) IBOutlet UITableView *sideTableView;
-(IBAction)showMessage;
#property (nonatomic, retain) NSArray *colorNames;
#end
I'm trying to get an image as a background to an existing tableview.
i'm getting an exception regarding: [sideTableViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7593640
please help i'm new in IOS programming!
may this code help you simply add the below code to just above
- (NSInteger)sideTableView:(UITableView *)sideTableView numberOfRowsInSection:(NSInteger)section
add this code
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
Any help will be appreciated, I've been stuck on this for quite a while. i added content to my UITableView and reload the data nothing happens and I cant quite figure out whats going on with my parkinglistviewcontroller. Well here's my code that I'm using.
.m File
#implementation ParkingListViewController
#synthesize objCustomCell;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
arrParkingList = [[NSMutableArray alloc] init];
appDelegate = [[UIApplication sharedApplication] delegate];
locationManager = [[CLLocationManager alloc] init];
arrAnnotations = [[NSMutableArray alloc] init];
// Do any additional setup after loading the view from its nib.
}
-(void)viewWillAppear:(BOOL)animated
{
[self locate];
[parkingMap setRegion:MKCoordinateRegionMakeWithDistance(parkingMap.userLocation.coordinate, 5, 5) animated:YES];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc
{
[locationManager release];
[tblParkingList release];
[parkingMap release];
[super dealloc];
}
- (void)viewDidUnload
{
[tblParkingList release];
tblParkingList = nil;
[parkingMap release];
parkingMap = nil;
[super viewDidUnload];
}
#pragma mark - Tableview Methods
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return arrParkingList.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
ParkingCustomCell *cell = (ParkingCustomCell*)[tableView dequeueReusableCellWithIdentifier:#"CellIdentifier"];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:#"ParkingCustomCell" owner:self options:nil];
cell = self.objCustomCell;
self.objCustomCell = nil;
}
ClsParking *objTmpParking = [arrParkingList objectAtIndex:indexPath.row];
cell.lblTitle.text = objTmpParking.strLocation;
cell.imgUserImage.layer.masksToBounds = YES;
cell.imgUserImage.layer.cornerRadius = 20;
[cell.imgUserImage setImageWithURL:[NSURL URLWithString:objTmpParking.strImageUrl] placeholderImage:nil];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 68;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ClsParking *objParking = [arrParkingList objectAtIndex:indexPath.row];
float fltLatitude = [objParking.strLatitude floatValue];
float fltLongitude = [objParking.strLongitude floatValue];
CLLocationCoordinate2D pLocation = CLLocationCoordinate2DMake(fltLatitude, fltLongitude);
[self setMapCenter:pLocation];
}
- (IBAction)btnAddTapped:(id)sender
{
ParkingNotificationViewController *objParkingNotificationViewController =[[ParkingNotificationViewController alloc] initWithNibName:#"ParkingNotificationViewController" bundle:nil];
[self presentViewController:objParkingNotificationViewController animated:YES completion:nil];
[objParkingNotificationViewController release];
}
- (IBAction)btnBackTapped:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
#end
.h file
#class ParkingCustomCell;
#interface ParkingListViewController : UIViewController <UITableViewDataSource,UITableViewDelegate,CLLocationManagerDelegate,MKMapViewDelegate>
{
IBOutlet UITableView *tblParkingList;
NSMutableArray *arrParkingList;
AppDelegate *appDelegate;
CLLocationManager *locationManager;
IBOutlet MKMapView *parkingMap;
NSMutableArray *arrAnnotations;
}
#property (nonatomic,retain) IBOutlet ParkingCustomCell *objCustomCell;
- (IBAction)btnAddTapped:(id)sender;
- (IBAction)btnBackTapped:(id)sender;
#end
And here's my parkingcustomcell class
#implementation ParkingCustomCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (void)dealloc {
[_lblTitle release];
[_imgUserImage release];
[super dealloc];
}
#end
In viewdidload method add the following :
self. tblParkingList.delegate = self;
self. tblParkingList.delegate = self;
Also #synthesize tblParkingList;
After that you have initialised an array arrParkingList for populating the table.Add content to it because it is empty.
In addition to AdamG's comment, I see you have allocated space for arrParkingList array, but I can't see where you add values to it/initialize it.
You should make sure that you set the class as the delegate for the tableview and the datasource delegate for the tableview. You can do this in the storyboarding by control dragging from the tableView to the icon on the left hand side of the bar, or by adding the following lines of code to your app..
self.tableView.delegate = self;
self.tableView.dataSource = self;
Also make sure that your tableView is declared as an outlet in your .h file. I am assuming you dragged it as an outlet called "tableView" in the above example.
Hope that helps!
pass data from FirstViewController to DetailViewController. i can not set the text of label in DetailViewController; FirstViewController is a tableview and it is good.
i use method updateRowNumber to set the rowNumber . and in DetailViewController, i can use debugger to see the rowNumber is correct. but the label's text is not showed on the view.
anyone can help me out?
in my FirstViewController
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (dvController == nil)
{
DetailViewController *aController = [[DetailViewController alloc] initWithNibName:#"DetailViewController" bundle:nil];
self.dvController = aController;
[aController release];
}
[[self navigationController] pushViewController:dvController animated:YES];
[dvController updateRowNumber:indexPath.row];
}
in my DetailViewController.h
#import <UIKit/UIKit.h>
#interface DetailViewController : UIViewController
{
int rowNumber;
IBOutlet UILabel *message;
}
#property(readwrite) int rowNumber;
#property(nonatomic, retain) IBOutlet UILabel *message;
- (void) updateRowNumber:(int) theindex;
#end
in my DetailViewController.m
#import "DetailViewController.h"
#interface DetailViewController ()
#end
#implementation DetailViewController
#synthesize message, rowNumber;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void) updateRowNumber: (int) theindex
{
rowNumber = theindex + 1;
message.text = [NSString stringWithFormat:#"row %i was clicked", rowNumber];
}
- (void)dealloc
{
[message release];
[super dealloc];
}
- (void)viewDidLoad
{
message.text = [NSString stringWithFormat:#"row %i was clicked ", rowNumber];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Do any additional setup after loading the view from its nib.
}
- (void)viewWillAppear:(BOOL)animated
{
//message.text = [NSString stringWithFormat:#"row %i was clicked ", rowNumber];
[super viewWillAppear: animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear: animated];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
You'll need to learn how the view is loaded, the process is well described in the documentation
What happens is that the view and all the outlets are nil until the view is loaded, you can make sure it is loaded by calling self.view; before configuring the outlet at updateRowNumber:
Please also note, you are better to call [super viewDidLoad] in the beginning of the overridden viewDidLoad, it makes sense as you need to let UIViewContorller to do it's staff before you do some customized logic, the dealloc is different as you need to do your logic before the standard NSObject -dealloc fires. Hope it's understandable.
I am using the following wrapper for SOAP web services: http://www.sudzc.com/
and the following MBProgressHUD for the activity indicador: https://github.com/jdg/MBProgressHUD
Don't know how i can use the MBProgressHUD before a view get call.
I'm also using a Data Controller where the call of the SOAP services is made.
Here is my code.
ProductoDataController.h
#import <Foundation/Foundation.h>
#class ProsoftProducto;
#interface ProductoDataController : NSObject
#property (nonatomic, copy) NSMutableArray *listaProductos;
- (NSUInteger)countOfListaProductos;
- (ProsoftProducto *)objectInListaProductosAtIndex:(NSUInteger)index;
- (void) agregarProductoWithNombre:(NSString *)pnombre
descripcion:(NSString *)pdescripcion
url:(NSString *)purl;
#end
ProductoDataController.m
#import "ProductoDataController.h"
#import "ProsoftProducto.h"
#import "ProsoftWS_PuenteAplicacionesMobiles.h"
#interface ProductoDataController()
- (void)inicializarDefaultLista;
#end
#implementation ProductoDataController
#synthesize listaProductos = _listaProductos;
- (void)inicializarDefaultLista
{
ProsoftWS_PuenteAplicacionesMobiles* service = [ProsoftWS_PuenteAplicacionesMobiles service];
service.logging = YES;
// service.username = #"username";
// service.password = #"password";
// Returns NSMutableArray*.
[service listaProductosActivos:self action:#selector(listaProductosActivosHandler:) detail: [NSMutableArray array]];
}
// Handle the response from listaProductosActivos.
- (void) listaProductosActivosHandler: (id) value {
// Handle errors
if([value isKindOfClass:[NSError class]]) {
NSLog(#"%#", value);
return;
}
// Handle faults
if([value isKindOfClass:[SoapFault class]]) {
NSLog(#"%#", value);
return;
}
// Do something with the NSMutableArray* result
self.listaProductos = (NSMutableArray*)value;
//NSLog(#"----- * LISTA PRODUCTOS ACTIVOS * -----");
}
- (void)setListaProductos:(NSMutableArray *)lista
{
if(_listaProductos != lista)
_listaProductos = [lista mutableCopy];
}
- (id)init
{
if(self = [super init])
{
[self inicializarDefaultLista];
return self;
}
return nil;
}
- (NSUInteger)countOfListaProductos
{
return [self.listaProductos count];
}
- (ProsoftProducto *)objectInListaProductosAtIndex:(NSUInteger)index
{
return [self.listaProductos objectAtIndex:index];
}
- (void) agregarProductoWithNombre:(NSString *)pnombre descripcion:(NSString *)pdescripcion
url:(NSString *)purl
{
ProsoftProducto *producto;
producto = [[ProsoftProducto alloc]initWithNombre:pnombre
descripcion:pdescripcion
url:purl];
[self.listaProductos addObject:producto];
}
#end
ProductoViewController.h
#import <UIKit/UIKit.h>
#class ProductoDataController;
#class MBProgressHUD;
#interface ProductoViewController : UITableViewController{
MBProgressHUD *HUD;
NSMutableArray *_objects;
}
#property (nonatomic, strong) ProductoDataController *dataControllerProductos;
#end
ProductoViewController.m
#import "ProductoViewController.h"
#import "ProductoDetalleViewController.h"
#import "ProductoDataController.h"
#import "ProsoftProducto.h"
/*
#interface ProductoViewController ()
NSMutableArray *_objects;
#end
*/
#implementation ProductoViewController
#synthesize dataControllerProductos = _dataControllerProductos;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Segue
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"PushProductoDetalle"]) {
ProductoDetalleViewController *detalleProductoViewController = [segue destinationViewController];
detalleProductoViewController.producto = [self.dataControllerProductos objectInListaProductosAtIndex:[self.tableView indexPathForSelectedRow].row];
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.dataControllerProductos countOfListaProductos];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"ProductoCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
ProsoftProducto *producto = [self.dataControllerProductos objectInListaProductosAtIndex:indexPath.row];
cell.textLabel.text = producto.nombre;
return cell;
}
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return NO;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:#"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
*/
}
#end
ProductoDetalleViewController.h
#import <UIKit/UIKit.h>
#class ProsoftProducto;
#interface ProductoDetalleViewController : UIViewController
#property (strong, nonatomic) ProsoftProducto *producto;
#property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
#property (weak, nonatomic) IBOutlet UILabel *lblTitulo;
#property (weak, nonatomic) IBOutlet UILabel *lblDescripcion;
#property (weak, nonatomic) IBOutlet UIImageView *imgUrl;
#end
ProductoDetalleViewController.m
#import "ProductoDetalleViewController.h"
#import "ProsoftProducto.h"
#interface ProductoDetalleViewController ()
#end
#implementation ProductoDetalleViewController
#synthesize producto = _producto;
#synthesize scrollView = _scrollView;
#synthesize lblTitulo = _lblTitulo;
#synthesize lblDescripcion = _lblDescripcion;
#synthesize imgUrl = _imgUrl;
- (void)setProducto:(ProsoftProducto *)pproducto
{
if(_producto != pproducto)
{
_producto = pproducto;
[self configurarView];
}
}
- (void)configurarView
{
ProsoftProducto *objProducto = self.producto;
if(objProducto)
{
self.lblTitulo.text = objProducto.nombre;
self.lblDescripcion.text = objProducto.descripcion;
CGSize maximumLabelSize = CGSizeMake(310,9999);
CGSize expectedLabelSize = [objProducto.descripcion sizeWithFont:_lblDescripcion.font
constrainedToSize:maximumLabelSize
lineBreakMode:_lblDescripcion.lineBreakMode];
CGRect newFrame = _lblDescripcion.frame;
newFrame.size.height = expectedLabelSize.height;
_lblDescripcion.frame = newFrame;
if(objProducto.urlImagen.length > 0){
self.imgUrl.image = [UIImage imageNamed:#"ic_offline.png"];
NSURL *url = [NSURL URLWithString:objProducto.urlImagen];
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
self.imgUrl.image = image;
} else {
_lblDescripcion.frame = CGRectMake(5, 40, 310, expectedLabelSize.height);
}
}
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[self configurarView];
NSUInteger height = 0;
CGSize maximumLabelSize = CGSizeMake(310,9999);
CGSize expectedLabelSize = [_producto.descripcion sizeWithFont:_lblDescripcion.font
constrainedToSize:maximumLabelSize
lineBreakMode:_lblDescripcion.lineBreakMode];
if(_producto.urlImagen.length > 0)
height = expectedLabelSize.height + 260;
else
height = expectedLabelSize.height + 40;
_scrollView.frame = (CGRect){_scrollView.frame.origin, CGSizeMake(320, 420)};
_scrollView.contentSize = CGSizeMake(320, height);
_scrollView.backgroundColor = [UIColor whiteColor];
[super viewDidLoad];
}
- (void)viewDidUnload
{
self.producto = nil;
[super viewDidUnload];
}
#end
Code of my aplicación delegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UINavigationController *navigatorController = [[tabBarController viewControllers] objectAtIndex:0];
// Solicitar Informacion
// Solicitar Informacion
// Productos
navigatorController = [[tabBarController viewControllers] objectAtIndex:1];
ProductoViewController *productoViewController = [[navigatorController viewControllers] objectAtIndex:0];
productoViewController.dataControllerProductos = [[ProductoDataController alloc]init];
// Productos
// Noticias
navigatorController = [[tabBarController viewControllers] objectAtIndex:2];
NoticiaViewController *noticiaViewController = [[navigatorController viewControllers] objectAtIndex:0];
noticiaViewController.dataControllerNoticias = [[NoticiaDataController alloc]init];
// Noticias
// Sucursales
navigatorController = [[tabBarController viewControllers] objectAtIndex:3];
SucursalViewController *sucursalViewController = [[navigatorController viewControllers] objectAtIndex:0];
sucursalViewController.dataControllerSucursal = [[SucursalDataController alloc]init];
// Sucursales
// Coopenae Virtual
navigatorController = [[tabBarController viewControllers]objectAtIndex:5];
InfoGeneralViewController *infoGeneralViewController = [[navigatorController viewControllers]objectAtIndex:0];
infoGeneralViewController.dataControllerInfoGeneral = [[InfoGeneralDataController alloc]init];
// Coopenae Virtual
// InfoGeneral
// InfoGeneral
return YES;
}
Can any help me to understand a bite of MBProgressHUD, i need to know were i have to call it.
THX
I have an array of objects, and i use following code to get in in the tableview
[source addObjectsFromArray:[UDdelegate naturArray]];
[[self tableView]reloadData];
My application fetch some data on location change, and that data is the objects in my naturArray. source is the list's datasource.
My problem is that if my list view is active while it is fetching the data, the list isn't updated. If i go to the main menu and back into the listView the data appear.
Is there a way to get the list to update while its active ?
Thanks.
Edit: Full code
VisListe.h:
#class UdINaturenAppDelegate;
#class POI;
#class webDetailView;
#interface VisListe : UITableViewController<UITableViewDelegate,UITableViewDataSource>
#property (nonatomic, retain,readwrite) IBOutlet NSMutableArray *dataSourceArray;
#property (strong, nonatomic) UdINaturenAppDelegate *UDdelegate;
#property (strong, nonatomic) POI *poi;
#property (strong, nonatomic) webDetailView *webView;
#property (strong, nonatomic) IBOutlet UITableView *tabel;
-(void)updateList;
-(NSString*)parseURL:(NSString*)url;
#end
VisListe.m:
#implementation VisListe
#synthesize dataSourceArray = source;
#synthesize UDdelegate;
#synthesize poi=_poi;
#synthesize webView = _webView;
#synthesize tabel = _tabel;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.navigationItem.title = NSLocalizedString(#"Poi List", nil);
UDdelegate = (UdINaturenAppDelegate*) [UIApplication sharedApplication].delegate;
source = [[NSMutableArray alloc]init];
_webView = [[webDetailView alloc] initWithNibName:#"webDetailView" bundle:nil];
[self updateList];
}
return self;
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
//[source addObjectsFromArray:[UDdelegate naturArray]];
}
- (void)viewDidUnload
{
[self setTabel:nil];
[super viewDidUnload];
self.dataSourceArray = nil; // this will release and set to nil
source = nil;
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
NSLog(#"unload");
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self updateList];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
// to determine specific row height for each cell, override this.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return ([indexPath row] == 0) ? 60.0 : 60.0;
}
// to determine which UITableViewCell to be used on a given row.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//return [UDdelegate naturArray].count;
return [source count];
}
//
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
_poi = [source objectAtIndex:indexPath.row];
cell.textLabel.text = [_poi title];
cell.detailTextLabel.text = [NSString stringWithFormat:#"Afstand: %f m.", [_poi dist]];
//[cell.imageView setImage:<#(UIImage *)#>];
return cell;
}
#pragma mark -
#pragma mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
_poi = [source objectAtIndex:indexPath.row];
NSLog(#"%#",[_poi title]);
NSString* u = [self parseURL:[_poi webUrl]];
[_webView setIncUrl:u];
[[self navigationController] pushViewController:_webView animated:YES];
}
-(NSString*)parseURL:(NSString*)url{
NSString* s = [url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
return s;
}
-(void)updateList{
[source removeAllObjects];
[source addObjectsFromArray:[UDdelegate naturArray]];
[_tabel reloadData];
}
-(UIImage*)setImgFromUrl:(NSString*)url{
NSURL *newurl = [NSURL URLWithString: url];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL: newurl]];
return image;
}
When the location is fetched the updateList method is called from the AppDelegate.m
Turned out that it was just me who was a little impatient. the [_tabel reloadData] method is just a little "heavy" to call, so the list was in fact updated, but it just took a little while to update.