tableviewcellForRowAtIndexPath is not being called - iphone

I have this basic shopping list app where in the first view there are two text fields. One that is the name of the item and the other is the item quantitiy. Once the user types those two entries and presses the save button, the app segues to the table view controller where the entries are stored first into an object called item, and then the object is stored into an array of items. Then I implement all the required table view methods and have the item displayed in a table view. Sadly, nothing is being displayed. When I save an entry the table view appears blank. After doing some debugging with NSLog's, I figured out that the crucial method tableviewcellForRowAtIndexPath is not being called. I found that others had a similar question and that the solution was to set the tableviewcontroller as the delegate, I tried that but it didn't work. Do you know what's wrong with my code? Thanks.
Here is my view controller for the first image, then I will show you my tableviewController code
#import "TVViewController.h"
#import "TableViewController.h"
//#import "TableViewController.m"
#implementation TVViewController
#synthesize title;//one of the text fields
#synthesize subtitle;//the other text field
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:#"Save"]) {
NSString *string1 = self.title.text;
NSString *string2 = self.subtitle.text;
[segue.destinationViewController addName: string1 andNumber:string2];
}
}
- (void)didReceiveMemoryWarning
{
[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, typically from a nib.
}
- (void)viewDidUnload
{
[self setTitle:nil];
[self setSubtitle:nil];
[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 != UIInterfaceOrientationPortraitUpsideDown);
}
#end
That is my viewcontroller
This is my table view controller, ignore the nslog's those were for debugging purposes
#import "TableViewController.h"
#import "Item.h"
#implementation TableViewController
#synthesize items;
-(void) addName:(NSString *) name
andNumber:(NSString *) numberOfItems
{
Item *item = [[Item alloc] init];
item.itemName = name;
item.itemQuantity = numberOfItems;
[self.items addObject:item];
NSLog(#"Data has been passed");
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
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];
NSLog(#"VIew is ready");
//[self.tableView reloadData];
// 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
{
NSLog(#"list initialized by count");
// Return the number of rows in the section.
return [self.items count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Item in cart";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
Item *item = [self.items objectAtIndex:indexPath.row];
cell.textLabel.text = item.itemName;
cell.detailTextLabel.text = item.itemQuantity;
return cell;
}

as far as I remember you need to set tableVeiw's dataSource for this, delegate is for recieveing events
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDataSource_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UITableViewDataSource

Related

UItbaleview Cell json contents not displayed in iOS

I created an app which will fetch info from web service.So far i got it by displaying the contents using NSLog but when i tried to load it in UITableViewCell its not displayed.Here is my code for that
#import "TableViewController.h"
#import "JSON.h"
#import "SBJsonParser.h"
#interface TableViewController ()
#end
#implementation TableViewController
#synthesize jsonurl,jsondata,jsonarray;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
jsonurl=[NSURL URLWithString:#"http://minorasarees.com/category.php"];
jsondata=[[NSString alloc]initWithContentsOfURL:jsonurl];
self.jsonarray=[jsondata JSONValue];
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;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#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 [jsonarray count];
}
- (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];
}
NSLog(#"1");
NSLog(#"%#",jsonarray);
cell.textLabel.text=[jsonarray objectAtIndex:indexPath.row];
NSLog(#"2");
return cell;
}
-(void)dealloc
{
[super dealloc];
[jsonarray release];
[jsondata release];
[jsonurl release];
}
#end
i've inserted tableviewcontroller by adding file with UITableViewController..will that be a problem..Help please..
Your JSON contains an array of dictionaries, so you're setting the text in your table view cell to an dictionary which cannot work since a string is expected. This actually should crash.
To solve that set your text to the category property of that dictionary:
cell.textLabel.text=[[jsonarray objectAtIndex:indexPath.row] valueForKey: #"category"];
besides this there are other things wrong with your code: [super dealloc] needs to be the last thing you call in your dealloc method. And you really should be using asynchronous networking code, blocking the main thread with networking is not acceptable.

Attempting to use table view in ios, getting error

I have a table view in my iOS tabbed application, but I can't run the app, I get this error at runtime:
3/23/12 10:15:23.119 PM CodeCompanion: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "2-view-16" nib but didn't get a UITableView.'
*** First throw call stack:
(0x13bd052 0x154ed0a 0x1365a78 0x13659e9 0x2436ae 0xda5cb 0xf5b89 0xf59bd 0xf3f8a 0xf3e2f 0xf1ffb 0xf285a 0xdbfbf 0xdc21b 0xdd0f1 0x4bfec 0x51572 0x4b72b 0x3abc2 0x3ace2 0x3aea8 0x41d9a 0x12be6 0x138a6 0x22743 0x231f8 0x16aa9 0x12a7fa9 0x13911c5 0x12f6022 0x12f490a 0x12f3db4 0x12f3ccb 0x132a7 0x14a9b 0x2888 0x27e5)
My View Controller header file is below:
#import <UIKit/UIKit.h>
#class LanguageTableViewCell;
#interface LanguagesViewController : UITableViewController {
NSArray *languages;
}
#property (nonatomic, retain) NSArray *languages;
#end
and my implementation file is:
#import "LanguagesViewController.h"
#import "LanguageTableViewCell.h"
#implementation LanguagesViewController
#synthesize languages;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"getting cell for row at index path: %i", [indexPath row]);
LanguageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"languageBase"];
if (cell == nil) {
cell = [[LanguageTableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"languageBase"];
}
[cell setName:[languages objectAtIndex:[indexPath row]]];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(#"rows in section: %i is: %i", section, [languages count]);
return [languages count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
NSLog(#"getting number of sections (1)");
return 1;
}
- (void)didReceiveMemoryWarning
{
[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, typically from a nib.
NSLog(#"view loaded, setting array");
languages = [NSArray arrayWithObjects:#"Java", nil];
}
- (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
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
#end
I'm pretty new to xcode and objective-c, so mention anything that could have gone wrong. I have set the ViewController of the table view to my above class, and I am not getting any errors or warnings in xcode. The table view is one of those dynamic ones that use prototype cells. If I need to post the class of the cell, I will.
By the looks of your error message you're using a nib file, "2-view-16", to layout your view but it doesn't contain a UITableView (or it isn't hooked up).
The LanguagesViewController inherits from UITableViewController which is looking for a UITableView to control which doesn't exist.
If you're using a nib to setup the view, you'll need to add a UITableView to the nib and set it to be the tableView of your LanguagesViewController.

Two uipicker in the same view

what i am trying to do is to put two uipickers on the same view, i read somewhere that one of them should have its own separate delegate i tried to do so but i couldn't make it work properly.
Some times when i run the application the second application just stops working with no errors on the console.
this is the .h file for the view:
#interface FirstViewController : UIViewController {
IBOutlet UIPickerView *cities;
NSMutableArray *array;
NSString *picked;
}
#property(nonatomic,retain) IBOutlet UIPickerView *cities;
#property(nonatomic,retain) IBOutlet NSMutableArray *array;
and here is the .m:
#implementation FirstViewController
#synthesize cities,array;
-(void) getCities:(NSString *)link{
url=link;
NSString *str=[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
if([str length]==0){
[str release];
return;
}
SBJsonParser *parser=[[SBJsonParser alloc] init];
array=[[parser objectWithString:str] copy];
[receivedData release];
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { // This method needs to be used. It asks how many columns will be used in the UIPickerView
return 1; // We only need one column so we will return 1.
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { // This method also needs to be used. This asks how many rows the UIPickerView will have.
return [array count]; // We will need the amount of rows that we used in the pickerViewArray, so we will return the count of the array.
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { // what happens when selecting rows
picked=[array objectAtIndex:row];
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { //method asks for what the title or label of each row will be
return [array objectAtIndex:row]; // We will set a new row for every string used in the array.
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[sv setScrollEnabled:TRUE];
[sv setContentSize:CGSizeMake(320, 800)];
[self getCities:#"any url"];
[super viewDidLoad];
}
- (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
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc
{
[super dealloc];
}
#end
and for the second uipicker i added an nsobject to the view and changed its class to "SecondPickerDelegate" which i created before and this is its code:
.h
#import <UIKit/UIKit.h>
#interface FirstViewSecondPickerDelegate : UIViewController<UIPickerViewDelegate>{
IBOutlet UIPickerView *specialities;
NSMutableArray *array;
NSString *picked;
}
#property(nonatomic,retain) IBOutlet UIPickerView *specialities;
#property(nonatomic,retain) NSMutableArray *array;
#property(nonatomic,retain) NSString *picker;
#end
the .m file:
#import "FirstViewSecondPickerDelegate.h"
#import "JSON.h"
#implementation FirstViewSecondPickerDelegate
#synthesize specialities,array,picker;
-(void) getSpecialities:(NSString *)link{
url=link;
NSString *str=[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:url]];
if([str length]==0){
[str release];
return;
}
SBJsonParser *parser=[[SBJsonParser alloc] init];
array=[[parser objectWithString:str] copy];
for(int i=0;i<[array count];i++){
NSLog(#"index %i",i);
NSLog(#"value %#",[array objectAtIndex:i]);
}
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView { // This method needs to be used. It asks how many columns will be used in the UIPickerView
return 1; // We only need one column so we will return 1.
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component { // This method also needs to be used. This asks how many rows the UIPickerView will have.
return [array count]; // We will need the amount of rows that we used in the pickerViewArray, so we will return the count of the array.
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { // what happens when selecting rows
picked=[array objectAtIndex:row];
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { //method asks for what the title or label of each row will be
return [array objectAtIndex:row]; // We will set a new row for every string used in the array.
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
picked=#"1";
[self getSpecialities:#"http://localhost:8080/Test/gs"];
}
return self;
}
/*
-(void) viewDidLoad{
[super viewDidLoad];
}
*/
- (void)dealloc
{
[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
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
If any one has a working example for such case please help.
You don't need separate delegates for two UIPickerView's in the same view.
Use the UIPickerView tag property, and then you can differentiate between them in delegate methods.

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?