Add group table view sections on iOS app? - iphone

Okay, so I'm writing an iPhone application, and to load the data into the grouped table views, I created a data model:
DataModel.m
#import "GeometryDataModel.h"
#implementation GeometryDataModel
#synthesize titleGeo =_titleGeo;
-(id)initWithTitleGeo:(NSString *)titleGeo
{
if ((self = [super init])) {
self.titleGeo = titleGeo;
}
return self;
}#end
Then I continued to write a data table...
DataTable.m
#import "GeometryTableData.h"
#import "GeometryDataModel.h"
#implementation GeometryTableData
#synthesize dataGeo = _dataGeo;
#synthesize thumbImageGeo = _thumbImageGeo;
- (id)initWithTitleGeo:(NSString *)titleGeo thumbImageGeo:(UIImage *)thumbImageGeo {
if ((self = [super init]))
{
self.dataGeo = [[GeometryDataModel alloc] initWithTitleGeo:titleGeo];
self.thumbImageGeo = _thumbImageGeo;
}
return self;
}
#end
then I created a view controller to set it all up
ViewController.m
#import "GeometryViewController.h"
#import "GeometryTableData.h"
#import "GeometryDataModel.h"
#interface GeometryViewController ()
#end
#implementation GeometryViewController
#synthesize geoCalculatorList = _geoCalculatorList;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
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)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#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
{
return _geoCalculatorList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *geoCell = [tableView dequeueReusableCellWithIdentifier:#"Geometry"];
GeometryTableData *geoTableStuff = [self.geoCalculatorList objectAtIndex:indexPath.row];
geoCell.textLabel.text = geoTableStuff.dataGeo.titleGeo;
geoCell.imageView.image = geoTableStuff.thumbImageGeo;
return geoCell;
}
#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
And then finally, in the AppDelegate.m file I implement it to the table:
sectionOne = [[TableData alloc] initWithTitle:#"A cell" thumbImage:[UIImage
imageNamed:#"none.png"]];
sectionTwo = [[TableData alloc] initWithTitle:#"Another separated cell" thumbImage:[UIImage
imageNamed:#"none.png"]];
NSMutableArray *TableData = [NSMutableArray arrayWithObjects:sectionOne,sectionTwo, nil];
UITabBarController * tabController = (UITabBarController *) self.window.rootViewController;
ViewController * algebraController = [tabController.viewControllers objectAtIndex:0];
Controller.calculatorList = TableData;
My question is, how would I create sections in the grouped table view, say to put "sectionOne" and "sectionTwo" into different sections on the table using my current system?
Thanks!!!

I'm not sure what you mean by putting "sectionOne" and "sectionTwo" in different sections. Do you want them to be the section views? In general, you put data in sections by having an array that's more complicated than a simple array. It could take several forms, an array of arrays is probably the simplest. If your data is set up that way, then you pass theData.count in numberOfSectionsInTableView and [[theData indexAtObject:section] count] in numberOfRowsInSection. In cellForRowAtIndexPath you would use something like this:
cell.textLabel.text = [[theData objectAtIndex:indexPath.section] objectAtIndexPath:indexPath.row];
You can use the new array syntax to shorten that to :
cell.textLabel.text = theData[indexPath.section][indexPath.row];

Related

How to construct a menu with a drill down table pointing to other ViewControllers in Xcode

I'm new to Objective-C, I like it,
I'm developping a free application for the local firefighters.
The app does nothing really hard, but I have a big problem with the main menu:
I have already created a table content all the section of my application, I am trying to implement the drill down method by means I can access to other ViewControllers, but I really don't know how to do it, I googled a lot but I've only found fragmentary documentation referenced to old versions of Xcode.
I'm using version 4.5.2 and the storyboard.
Here is the menu.h
#import <UIKit/UIKit.h>
#interface Menu : UITableViewController
#property (nonatomic, retain) NSMutableArray *listaMenu; //questo sarà il mio array contentente le varie opzioni della tabella
#end
And the menu.m
#import "Menu.h"
#import "News.h"
#interface Menu ()
#end
#implementation Menu
#synthesize listaMenu; //creo i metodi getter e setter
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Menu";
//Elementi da visualizzare nella tabella
listaMenu = [[NSMutableArray alloc] initWithObjects: #"News", #"Memebri", #"Calendario", #"Interventi", #"Galleria", #"Mezzi", #"Reclutamento", nil];
// 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)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//funzione in cui va inserito il numero di righe da visualizzare
return [listaMenu count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = nil;
cell =[tableView dequeueReusableCellWithIdentifier:#"PlistCell"];
if(cell == nil){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"PlistCell"];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
cell.textLabel.text = [listaMenu objectAtIndex:indexPath.row];
return cell;
}
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath //Rende gli oggetti NON editabili
{
// Return NO if you do not want the specified item to be editable.
//return YES;
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
I hope my problem is well explained.
Thank you very much!
You need to read up about UISegue - this is the object that handles transitions from one UIViewController to another controller. In Interface Builder you can Ctrl-Drag to create a Segue between, say a UIButton and the desired UIViewController. This is the simplest usage of segues.
If you need to pass data to the destination UIViewController then you'll need to implement the - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender method. Within this method you can get the segue.destinationViewController and then send it whatever data you need. N.B. The destination view controller's view has not loaded yet, so if you're trying to customise UIViews directly, then they won't exist. You can fudge it by doing [segue.destinationViewController view] to get going, although it would be better to configure non-UI properties and have the view controller itself do any necessary customisation in viewDidLoad.

TableView wont display provided data

I am having a strange issue with TableView. Here is some code to clarify everything:
I am using tabbed panes and this right here is just one of my two ViewControllers:
As you can see, all I do is setting up an UIView and placing a tableView right ontop of it.
#import "SuchenCtrl.h"
#interface SuchenCtrl ()
#end
#implementation SuchenCtrl
#synthesize MainView;
#synthesize Standort;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view = self.MainView;
[self.Standort.tableView setDelegate:self.Standort];
[self.Standort.tableView setDataSource:self.Standort];
[self.MainView addSubview:self.Standort.tableView];
}
- (id)init {
self = [super init];
if(self) {
CGRect rect = [[UIScreen mainScreen] applicationFrame];
self.MainView = [[UIView alloc] initWithFrame:rect];
[self.MainView setBackgroundColor:[UIColor blackColor]];
//Alloc UITableViewController
self.Standort = [[UIStandort alloc] initWithStyle:UITableViewStylePlain];
[self.Standort release];
[self.MainView release];
}
return self;
}
#end
Now UIStandort is another class that simply inherits from UITableViewController. It implements all necessary functions to display data. All im trying to achieve is having the table display "Test" a couple of times but it wont. The table gets displayed nicely but just with empty cells. When I breakpoint one of the implemented functions in the class UIStandort nothing gets called, so my assumption is that the delegate and sourceData are pointing to wrong classes? Though, I explicitly assign those before putting the table on the view.
UIStandort* Standort is declared with properties retain and nonatomic if this helps.
#import "UIStandort.h"
#interface UIStandort ()
#end
#implementation UIStandort
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath(NSIndexPath *)indexPath
{
UITableViewCell* cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
cell.textLabel.text = #"Test";
[cell autorelease];
return cell;
}
#end
Thanks.
You return 0 for the number of row in section. The documentation states:
The number of sections in tableView. The default value is 1.
Can you try:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

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.

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

Tableview not drilling down

Ok, Here is the code in my AppDelegate that loads the Schedule nib.
Schedule *newestVideoController = [[Schedule alloc] initWithNibName:#"Schedule" bundle:nil];
newestVideoController.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Schedule" image:[UIImage imageNamed:#"app-icon_2_newest.png"] tag:2];
NSArray *controllers = [NSArray arrayWithObjects:navController, newestVideoController, nil];
mainController.viewControllers = controllers;
Now here is my header file for schedule.
#import <UIKit/UIKit.h>
#import "AnotherViewController.h"
#interface Schedule : UITableViewController
<UITableViewDelegate, UITableViewDataSource> {
NSArray *mySchedule;
}
#property (nonatomic,retain) NSArray *mySchedule;
#end
Lastly here again is my implementaion file for "Schedule".
#import "Schedule.h"
#import "AnotherViewController.h"
#implementation Schedule
#synthesize mySchedule;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return mySchedule.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//create a cell
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"cell"];
//fill it with contents
cell.textLabel.text = [mySchedule objectAtIndex:indexPath.row];
//return it
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:#"AnotherViewController" bundle:nil];
[self.navigationController pushViewController:anotherViewController animated:YES];
[anotherViewController release];
}
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
return self;
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
NSString *myFile = [[NSBundle mainBundle] pathForResource:#"exercise" ofType:#"plist"];
mySchedule = [[NSArray alloc] initWithContentsOfFile:myFile];
[super viewDidLoad];
}
/*
// Override to allow orientations other than the default portrait orientation.
- (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.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
#end
Need more code/info. It looks like you implemented tableView:didSelectRowAtIndexPath: and pushed another View Controller onto the stack correctly, so it's hard to say. But here's a hit list:
Are you certain tableView:didSelectRowAtIndexPath: is getting called? Did you set a breakpoint? If not, you may have forgotten to set your Schedule class as the delegate either programatically or in Interface Builder.
Is schedule's navigation controller definitely set? That is, was it pushed onto a Navigation Controller stack?
Are you sure the nib file for AnotherViewController exists?