Buttons in iOS App won't show - iphone

I am creating an iPhone app, and I'm having some trouble with the TableView and adding buttons. I started with a regular view, and then added a table view, and then a couple buttons to the top, as shown here:
The problem is that when I run the app I get this:
Neither of the buttons that I added are there. Here is my .h file:
//
// RootBeerTVCViewController.h
// BaseApp
//
// Created by Blaine Anderson on 10/12/12.
// Copyright (c) 2012 UIEvolution, Inc. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface RootBeerTVCViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
#property (weak, nonatomic) IBOutlet UIButton *nameButton;
#property (weak, nonatomic) IBOutlet UIButton *locationButton;
#property(strong, nonatomic) NSMutableArray* rootList;
-(IBAction)sort:(id)sender;
#end
And here is the .M file:
//
// RootBeerTVCViewController.m
// BaseApp
//
// Created by Blaine Anderson on 10/12/12.
// Copyright (c) 2012 UIEvolution, Inc. All rights reserved.
//
#import "RootBeerTVCViewController.h"
#import "GlobalData.h"
#interface RootBeerTVCViewController ()
#end
#implementation RootBeerTVCViewController
#synthesize rootList;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[GlobalData sharedData].mViewManager.mNavController.navigationBarHidden=NO;
// Do any additional setup after loading the view from its nib.
rootList = [[GlobalData sharedData] mRootList ];
NSLog(#"RootList in view did load: %#", rootList);
UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];
tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
tableView.delegate = self;
tableView.dataSource = self;
//[tableView addSubview:sortingView];
[tableView reloadData];
self.view = tableView;
}
- (void)viewDidUnload
{
[self setLocationButton:nil];
[self setNameButton:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
rootList = [[GlobalData sharedData] mRootList ];
NSLog(#"RootList: %#", rootList);
// Return the number of sections.
NSLog(#"RootList count: %i", rootList.count);
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of sections.
NSLog(#"RootList row count: %i", rootList.count);
return rootList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
rootList =[[GlobalData sharedData].mRootBeerParser rootBeerList];
NSLog(#"RootList Cell: %#", rootList);
RootBeers* mRootBeer = [rootList objectAtIndex:indexPath.row];
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"Cell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
NSLog(#"Cell Name: %#", mRootBeer.brewer);
// Configure the cell...
cell.textLabel.text = mRootBeer.name;
cell.detailTextLabel.text = mRootBeer.location;
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 YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
RootBeers* mRootBeer =[rootList objectAtIndex:indexPath.row];
[GlobalData sharedData].mRootBeer = mRootBeer;
[[GlobalData sharedData].mViewManager pushView:DETAILVIEW animated:YES];
}
- (IBAction)sort:(id)sender {
rootList =[[GlobalData sharedData].mRootBeerParser rootBeerList];
[[GlobalData sharedData].mRootBeerParser sortRootBeerByName:rootList];
}
#end
If someone could give me an idea of what I'm doing wrong, that would be great. I hope that I have provided enough information, if not, please let me know and I'll be happy to supply more.

In your viewDidLoad you create a new UITableView of screen size and then set it as VC view, thus overriding the view that was loaded from xib. As a result you are only seeing the table you created in code.

Related

PFquery table view control show detail

I'm looking for a way to transport data entered into the database from a view to another. I have a table view controller with university exams inserted every examination must show your card, calling its data from the data browser to Parse the current user through the
- (void) prepareForSegue: (uistoryboardSegue)
Then I try to explain as best as possible ...
I downloaded from the project parse.com PFQueryTableViewController.
I entered all the data perfectly recall the Databrowser ...
My cells are thus created:
#import "TableViewParse.h"
#import "CustomNav.h"
#import "ListaInAttesa.h"
#implementation TableViewParse
#synthesize TableViewInAttesa;
- (id)initWithCoder:(NSCoder *)aCoder {
self = [super initWithCoder:aCoder];
// Custom the table
// The className to query on
self.parseClassName = #"miaclasse";
// The key of the PFObject to display in the label of the default cell style
self.textKey = #"titolomio";
// Whether the built-in pull-to-refresh is enabled
self.pullToRefreshEnabled = YES;
// Whether the built-in pagination is enabled
self.paginationEnabled = YES;
// The number of objects to show per page
self.objectsPerPage = 5;
[CustomNav NavBar];
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (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 - Parse
- (void)objectsDidLoad:(NSError *)error {
[super objectsDidLoad:error];
// This method is called every time objects are loaded from Parse via the PFQuery
}
- (void)objectsWillLoad {
[super objectsWillLoad];
// This method is called before a PFQuery is fired to get more objects
}
// Override to customize what kind of query to perform on the class. The default is to query for
// all objects ordered by createdAt descending.
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
[query whereKey: #"user" equalTo: [PFUser currentUser]];
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if ([self.objects count] == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
[query orderByAscending:#"createdAt"];
return query;
}
// Override to customize the look of a cell representing an object. The default is to display
// a UITableViewCellStyleDefault style cell with the label being the first key in the object.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell
cell.textLabel.text = [object objectForKey:#"titolomio"];
cell.detailTextLabel.text = [NSString stringWithFormat:#"Questo esame è previsto per il : %#", [object objectForKey:#"datamia"]];
return cell;
}
/*
// Override if you need to change the ordering of objects in the table.
- (PFObject *)objectAtIndex:(NSIndexPath *)indexPath {
return [objects objectAtIndex:indexPath.row];
}
*/
// Override to customize the look of the cell that allows the user to load the next page of objects.
// The default implementation is a UITableViewCellStyleDefault cell with simple labels.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForNextPageAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"NextPage";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = #"Visualizza ancora ....";
return cell;
}
#pragma mark - Table view data source
// 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 YES;
}
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
PFObject *object = [self.objects objectAtIndex:indexPath.row];
[object deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
[self loadObjects];
}];
}
}
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Esamiinattesa"])
{
// NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
// ListaInAttesa *destViewController = segue.destinationViewController;
// destViewController.title = [self.postController objectInListAtIndex:indexPath.row];
}
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
// [self performSegueWithIdentifier:#"Esamiinattesa" sender:indexPath];
}
#end
Now I need that when the user clicks on a current exam placed in the cell Tableview is sent to a specific viewcontroller where inside are called the results of the examination the time the user selected current ...
I know that it is "prepareForSegue" but I can not figure out where I'm wrong, maybe I'm wrong just the procedure to obtain the required result.
P.S.I realized just now that I connected with the user's findanzato because I changed my pc and I kept doing the same id logout ... Sorry ... We are working on this project in two App

StoryBoard iOS 5 - Custom UITableViewCell Crash Scrolling up

I have been coding a example of a UITableView with a custom UITableViewCell (PlayerCell). All work fine, I can see the elements in my table and I can select them, but when I do a scroll up, the app crash. I have reviewed the identifier, the class of the controller, everything, but when I use a custom cell, it not works. If I use a default style, it works fine, inclusive the scroll up.
I think I have the problem in this method: didSelectRowAtIndexPath
But the debugger, don't show me an error, only something like: EXEC BAD ADRESSS (I don't have the computer here)
This is my code:
MyTeamViewController.h
#import <UIKit/UIKit.h>
#interface MyTeamViewController : UITableViewController
#property (nonatomic, strong) NSMutableArray *players;
#end
MyTeamViewController.m
#import "MyTeamViewController.h"
#import "Player.h"
#import "PlayerCell.h"
#interface MyTeamViewController ()
#end
#implementation MyTeamViewController
#synthesize players;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
// Override point for customization after application launch.
players = [NSMutableArray arrayWithCapacity:20];
Player *player = [[Player alloc] init];
player.name = #"Bill Evans";
player.game = #"Tic-Tac-Toe";
player.rating = 4;
[players addObject:player];
player = [[Player alloc] init];
player.name = #"Oscar Peterson";
player.game = #"Spin the Bottle";
player.rating = 5;
[players addObject:player];
player = [[Player alloc] init];
player.name = #"Dave Brubeck";
player.game = #"Texas Hold’em Poker";
player.rating = 2;
[players addObject:player];
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//#warning Incomplete method implementation.
// Return the number of rows in the section.
NSUInteger numberCells = players.count;
return numberCells;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"PlayerCell";
PlayerCell *cell = (PlayerCell *)[tableView
dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
NSLog(#"Cell is NIL");
//I don't know what put here <-- MY PROBLEM!!! :(
}
Player *player = [self.players objectAtIndex:indexPath.row];
cell.nameLabel.text = player.name;
cell.pointsLabel.text = player.game;
cell.clubImageView.image = [self
imageForRating:player.rating];
// Configure the cell...
return cell;
}
- (UIImage *)imageForRating:(int)rating
{
switch (rating)
{
case 1: return [UIImage imageNamed:#"1StarSmall.png"];
case 2: return [UIImage imageNamed:#"2StarsSmall.png"];
case 3: return [UIImage imageNamed:#"3StarsSmall.png"];
case 4: return [UIImage imageNamed:#"4StarsSmall.png"];
case 5: return [UIImage imageNamed:#"5StarsSmall.png"];
}
return nil;
}
/*
// 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 YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#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];
[detailViewController release];
*/
}
#end
The other files:
Player.h
#import <Foundation/Foundation.h>
#interface Player : NSObject
#property (nonatomic, copy) NSString *name;
#property (nonatomic, copy) NSString *game;
#property (nonatomic, assign) int rating;
#end
Player.m
#import "Player.h"
#implementation Player
#synthesize name;
#synthesize game;
#synthesize rating;
#end
PlayerCell.h
#import <UIKit/UIKit.h>
#interface PlayerCell : UITableViewCell
#property (nonatomic, strong) IBOutlet UILabel *nameLabel;
#property (nonatomic, strong) IBOutlet UILabel *pointsLabel;
#property (nonatomic, strong) IBOutlet UIImageView
*clubImageView;
#end
PlayerCell.m
#import "PlayerCell.h"
#implementation PlayerCell
#synthesize nameLabel;
#synthesize pointsLabel;
#synthesize clubImageView;
- (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
}
#end
Thank you so much!!
EDIT: I solved it with: players = [[NSMutableArray arrayWithCapacity:20] retain];
I would try to remove the
- (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
}
In the PlayerCell.m - u don't need them.

Xcode 4.3 UITableView Blank

I'm firing up a UITableView View from a TabbedController page by clicking on a button.
The UITableView example was taken from LuisEGarza's excellent UITableView example on YouTube and to my belief is line perfect. The code compiles, but when the UITableView page comes up it is blank. Is this an issue with the TabbedController or have I done something else wrong?
Below are the sample .m and .h files.
//
// SolarResultsTableViewController.h
// Solar
//
// Created by Edward Hasted on 08/05/2012.
// Copyright (c) 2012 EHC. All rights reserved.
//
#import <UIKit/UIKit.h>
#interface SolarResultsTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
NSArray *tableData;
// IBOutlet UILabel *rowLabel;
}
#property (nonatomic, retain) NSArray *tableData;
#end
//
// SolarResultsTableViewController.m
// Solar
//
// Created by Edward Hasted on 08/05/2012.
// Copyright (c) 2012 EHC. All rights reserved.
//
#import "SolarResultsTableViewController.h"
#implementation SolarResultsTableViewController
#synthesize tableData;
- (void)viewDidLoad
{
tableData = [[NSArray alloc] initWithObjects:#"A", #"B", #"C", #"D", nil];
[super viewDidLoad];
// Do any additional setup after loading the view.
}
#pragma mark - TableView Data Source methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// rowLabel.text = [NSString stringWithFormat:#"%d", count];
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:#"MyCell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"MyCell"];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
- (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.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
Implement (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView method
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
I hope it will be helpful to you.

iOS tableView help

I am trying to make a tableView that will allow me to delete and add items. The biggest problem I am running into is that none of my cells will display. I'm not sure what I'm leaving out. Here's the TableViewController class
#import "GroceryListTableViewController.h"
#implementation GroceryListTableViewController
#synthesize groceries;
/*- (NSMutableArray *) groceries
{
if(groceries == nil)
[self addToGroceries:#"Groceries"];
return groceries;
}*/
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
self.groceries = [NSMutableArray arrayWithObjects:#"Steak", #"Juice", #"Stuff", nil];
if (self) {
}
return self;
}
-(void) addToGroceries:(NSString *)grocery
{
[self.groceries addObject:grocery];
}
- (void)dealloc
{
[groceries release];
[super dealloc];
}
- (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];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [self.groceries count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"GroceryListCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [self.groceries objectAtIndex:indexPath.section];
// Configure the cell...
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 YES;
}
*/
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#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];
[detailViewController release];
*/
}
#end
Thanks for any help. I think the problem is where I fill the list with items, but I have tried other things (such as a constructor), but they haven't worked either.
(I have edited to code to be the correct solution so the other questions were able to help)
Try this...although the rest of the code could use some review. ;)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

NSMutableArray doesn't get populated on view's first appearance

I'm using the Dropbox SDK to fill an array filePaths.
However the array is only filled the second time I open the corresponding view. When I open the view for the first time, the array is empty.
Does anyone know why this is?
Thanks in advance!
// DropboxFileViewController.m
#import "DropboxFileViewController.h"
#import "DropboxViewController.h"
#import "DropboxSDK.h"
#import <stdlib.h>
#interface DropboxFileViewController () <DBRestClientDelegate>
#property (nonatomic, readonly) DBRestClient* restClient;
#end
#implementation DropboxFileViewController
#synthesize dropboxFileView;
#synthesize filePaths;
- (void)restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata {
//NSArray* validExtensions = [NSArray arrayWithObjects:#"pdf", #"docx", #"doc", nil];
NSMutableArray* newDropboxFilePaths = [NSMutableArray new];
for (DBMetadata* child in metadata.contents) {
//NSString* extension = [[child.path pathExtension] lowercaseString];
//if (!child.isDirectory && [validExtensions indexOfObject:extension] != NSNotFound) {
[newDropboxFilePaths addObject:child.path];
//}
}
[filePaths release];
filePaths = newDropboxFilePaths;
}
/*- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}*/
#pragma mark -
#pragma mark Initialization
/*
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
self = [super initWithStyle:style];
if (self) {
// Custom initialization.
}
return self;
}
*/
#pragma mark -
#pragma mark View lifecycle
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.restClient loadMetadata:#"/"];
}
- (DBRestClient*)restClient {
if (restClient == nil) {
restClient = [[DBRestClient alloc] initWithSession:[DBSession sharedSession]];
restClient.delegate = self;
}
return restClient;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[dropboxFileView reloadData];
}
/*
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
}
*/
/*
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [filePaths count];
//NSLog(#"deze shit wordt geinvoked vriend");
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
//NSDictionary *dictionary = [listOfItems objectAtIndex:indexPath.section];
NSUInteger row = [indexPath row];
cell.textLabel.text = [filePaths objectAtIndex:row];
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 YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
#pragma mark -
#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];
[detailViewController release];
*/
}
#pragma mark -
#pragma mark Memory management
- (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 {
[super dealloc];
}
#end
your observation might be wrong.
I guess DBRestClient does its work in another thread. And shortly after you've left viewWillAppear the tableview gets its data. And at this time the DBRestClient isn't finished.
To fix this simply reload the tableview when you get the data
Append [dropboxFileView reloadData]; to - (void)restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata