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!
Related
In my app I have a UITabBarController which has four view controllers. In every view controller I have a collection view. In each collection view I have some images. When I select an image from the third view controller it opens a web view controller which is not in UITabBarController.
In web view controller I have a back button on top with navigation bar. After pressing that back button it's coming back to third view controller. Again when I select another image in third view controller, it should open the web view controller, but the web view controller didn't appear on simulator instead saying error 1thread,1breakpoint.
Here is my code:
This code is in thirdviewcontroller after selecting the image
webViewController = [[AppsWebViewController alloc]init];
[self presentViewController:webViewController animated:YES completion:nil];
This code is in webviewcontroller after pressing the back button
[self dismissViewControllerAnimated:YES completion:nil];
I need the webviewcontroller to open every time after selecting any image in any of the four view controllers.
my thirdviewcontroller code:
#import "FreqAppsThirdViewController.h"
#interface FreqAppsThirdViewController ()
#end
#implementation FreqAppsThirdViewController
- (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.
icons = [NSArray arrayWithObjects:#"amazon-1.png",#"best_buy.png",#"Carl-Icahn-Lectures-Apple-Gambles-Netflix-and-Threatens-eBay-2.jpg",#"index.jpg",#"Office-Max.jpg", nil];
UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
_collectionView=[[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:layout];
[_collectionView setDataSource:self];
[_collectionView setDelegate:self];
[_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:#"cellIdentifier"];
[_collectionView setBackgroundColor:[UIColor whiteColor]];
[self.view addSubview:_collectionView];
[super viewDidLoad];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return icons.count;
}
// The cell that is returned must be retrieved from a call to - dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:#"cellIdentifier" forIndexPath:indexPath];
cell.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:[icons objectAtIndex:indexPath.row]]];
return cell;
}
-(void)collectionView:(UICollectionView *)collectionViewdidSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
NSURL *url = [NSURL URLWithString:#"http://www.amazon.com/"];
webViewController = [[FreqAppsWebViewController alloc]initWithURL:url andTitle:#"Amazon"];
[self presentViewController:webViewController animated:YES completion:nil];
} else if (indexPath.row == 1){
NSURL *url = [NSURL URLWithString:#"http://www.bestbuy.com/"];
webViewController = [[FreqAppsWebViewController alloc]initWithURL:url andTitle:#"Best Buy"];
[self presentViewController:webViewController animated:YES completion:nil];
} else if (indexPath.row == 2){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.ebay.com"]];
} else if (indexPath.row == 3){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.walmart.com"]];
} else if (indexPath.row == 4){
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.officemax.com"]];
}
// datasetCell.backgroundColor = [UIColor blueColor]; // highlight selection
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout (UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(50, 50);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout(UICollectionViewLayout*)collectionViewLayoutinsetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(50, 20, 50, 20);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
my webviewcontroller code:
#import "FreqAppsWebViewController.h"
#import "FreqAppsThirdViewController.h"
#import "FreqAppsAppDelegate.h"
#interface FreqAppsWebViewController ()
#end
#implementation FreqAppsWebViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (id)initWithURL:(NSURL *)url andTitle:(NSString *)string {
if( self = [super init] ) {
theURL = url;
theTitle = string;
}
return self;
}
-(id)initWithURL:(NSURL *)url {
return [self initWithURL:url andTitle:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
webTitle.title = theTitle;
NSURLRequest *requestObject = [NSURLRequest requestWithURL:theURL];
[webView loadRequest:requestObject];
}
- (IBAction) back:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
webView.delegate = nil;
[webView stopLoading];
}
#end
my webviewcontroller.h code
#import <UIKit/UIKit.h>
#interface FreqAppsWebViewController : UIViewController <UIWebViewDelegate>
{
NSURL *theURL;
NSString *theTitle;
IBOutlet UIWebView *webView;
IBOutlet UINavigationItem *webTitle;
}
- (id)initWithURL:(NSURL *)url;
- (id)initWithURL:(NSURL *)url andTitle:(NSString *)string;
- (IBAction)back:(id)sender;
#end
my thirdviewcontroller.h code:
#import <UIKit/UIKit.h>
#import "FreqAppsWebViewController.h"
#interface FreqAppsThirdViewController:UIViewController<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
{
UICollectionView *_collectionView;
NSArray *icons;
FreqAppsWebViewController *webViewController;
}
#end
Copy and paste the full error message you're getting.
If it is a breakpoint, not an error, as you seem to be indicating, it might just be that you clicked on a the margin of your source and set a breakpoint without realizing it.
To check for breakpoints:
Press Command 7 to display the breakpoint navigator and see if there are any breakpoints set in your code. If there are, you'll an outline starting with the target (the current app) then the source file .m, and then an entry listing a method name and line number, with a symbol that looks like a cross between a right-pointing arrow and a blue sticky note.
If there are breakpoints, select them one at a time and note where they are in your code. Are then in your IBAction method, or the one of the methods in your AppsWebViewController?
Delete each breakpoint by selecting it and pressing the delete key. Then run your program again.
I did an empty project on UITable Cells and it worked. Using the same code I added in to an existing project where there are multiple xib linked. When navigating from another xib to this page, the table cells did appear but the content and the required number of cells did not run.
Below is the code of my current project:
OptionViewController.m:
#import "OptionViewController.h"
#import "FishAppDelegate.h"
#import "MainViewController.h"
#import "PetFishViewController.h"
#import "MarineFishViewController.h"
#interface OptionViewController ()
#end
#implementation OptionViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title =#"Choose a category :)";
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)PetFish:(id)sender
{
PetFishViewController *petFish = [[PetFishViewController alloc]initWithNibName:nil bundle:nil];
[[self navigationController] pushViewController:petFish animated:YES];
}
// this is the sub class containing table cells
-(IBAction)MarineFish:(id)sender
{
MarineFishViewController *MarineFish = [[MarineFishViewController alloc]initWithNibName:nil bundle:nil];
[[self navigationController] pushViewController:MarineFish animated:YES];
}
#end
At the current sub class: marine fish
MarineFishController.h
#import <Foundation/Foundation.h>
#interface MarineFishViewController : UITableViewController
{
NSMutableArray *fishList;
}
#end
MarineFishController.m :
#import "MarineFishViewController.h"
#import "MarineFish.h"
#implementation MarineFishViewController
{
/*NSArray *tableData;
NSArray *thumbnail;
*/
}
-(id) init{
//call the superclass
self = [super initWithStyle:UITableViewStyleGrouped];
if(self){
fishList = [[NSMutableArray alloc] init];
MarineFish *Item1 = [[MarineFish alloc] initWithName:#"Shark" imageName:#"Sea.jpg"];
[fishList addObject:Item1];
}
return self;
}
-(id)initWithStyle:(UITableViewStyle)style{
return [self init];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [fishList count];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//create an instance of uitableviewcell
//check for a reusable cell first, use if exist
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"UITableViewCell"];
//if there is no reusable cell of this type,create new one
if(!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"UITableViewCell"];
}
//set text on the cell
MarineFish *p = [fishList objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[[NSString alloc] initWithFormat:#"%#",[p fishName]]];
}
#end
Regarding to the table. I only added one item to the fish list which is item1 and hence should only have one cell in display.
You don't need to override init and initWithStyle: methods. Move your code from init to viewDidLoad
- (void)viewDidLoad
{
[super viewDidLoad];
fishList = [[NSMutableArray alloc] init];
MarineFish *Item1 = [[MarineFish alloc] initWithName:#"Shark" imageName:#"Sea.jpg"];
[fishList addObject:Item1];
}
EDIT
Error was so oblivious...
-(UITableViewCell*)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
Must return a UITableViewCell object. So put return cell; at the end. Here is edited MarineFishViewController.m.
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.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
UITableViewController not loading data
I have created a UITableViewController in the following way
#import "KLActionsViewController.h"
#interface KLActionsViewController ()
#end
#implementation KLActionsViewController
#synthesize actionList,delegate;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)loadView
{
}
- (void)viewDidLoad {
[super viewDidLoad];
NSMutableArray* list = [[NSMutableArray alloc] init];
self.tableView = [[UITableView alloc] init];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.actionList = list;
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 400.0);
[self.actionList addObject:#"Obj1"];
[self.actionList addObject:#"Obj2"];
[self.actionList addObject:#"Obj3"];
[self.actionList addObject:#"Obj4"];
}
- (int)numberOfSectionsInTableView:(UITableView *)tableView
{
NSLog(#"in number of section");
return 1;
}
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSString* lab = [self.actionList objectAtIndex:indexPath.row];
// NSLog(lab);
NSLog(#"here in there");
cell.textLabel.text = lab;
return cell;
}
- (NSInteger)numberOfRowsInSection:(NSInteger)section
{
NSLog(#"Total entries : %i ",[self.actionList count]);
return [self.actionList count];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.delegate != nil) {
[self.delegate actionSelected:indexPath.row];
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
self.actionList = nil;
self.delegate = nil ;
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
But when I try to create it's instance and show it in a UIPopoverController all I can see is an empty table and no data in it. Also, numberOfRowsInSection and cellForRowAtIndexPath never get called.
Any help ?
You are creating a new table view inside viewDidLoad: but not making it a subview of this controller's view. Since you say you see an empty table, this leads me to believe that you're loading one table from your .xib file, but setting the dataSource only of this new one.
If that's how it's structured, use a connection in the .xib from the table view to the self.tableView property and don't create a new object...just configure the one you have.
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.