1

I am creating a Two Level table view. And the second view is supposed to have the list of the movies I have listed below in my viewDidLoad method, but it is not showing.(You can see my screen shots attached)Does anyone know which file where I can look to see why it is not showing? The code below is from my DisclosureButtonController.m file which is to display this information after I hit the Disclosure Buttons instance on the First Level screen.

Regards,

first screen that is up the screen that should show the Movies Listed from my viewDidLoad Method

#import "LWWDisclosureButtonController.h"
#import "LWWAppDelegate.h"
#import "LWWDisclosureDetailController.h"

@interface LWWDisclosureButtonController ()
@property (strong, nonatomic) LWWDisclosureDetailController *childController;
@end

@implementation LWWDisclosureButtonController

@synthesize list;
@synthesize childController;

//- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//{
//  self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
//if (self) {
    // Custom initialization
//}
//return self;
//}
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *array = [[NSArray alloc] initWithObjects:@"Toy Story", @"A Bug's Life", @"Toy     Story 2", @"Monsters, Inc.", @"Finding Nemo", @"The Incredibles", @"Cars", @"Ratatouille",    @"WALL-E", @"Up", @"Toy Story 3", @"Cars 2", @"Brave", nil];
 self.list = array;
// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
[super viewDidUnload];
self.list = nil;
self.childController = nil;
// Release any retained subviews of the main view.
}

#pragma mark -
#pragma mark Table Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [list count];//
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:   (NSIndexPath *)indexPath
{
static NSString * DisclosureButtonCellIdentifier = @"DisclosureButtonCellIdentifier";

UITableViewCell *cell = [tableView   dequeueReusableCellWithIdentifier:DisclosureButtonCellIdentifier];

if (cell == nil)
{
    cell = [[UITableViewCell alloc]
            initWithStyle:UITableViewCellStyleDefault
            reuseIdentifier:DisclosureButtonCellIdentifier];
}
NSUInteger row = [indexPath row];
NSString *rowString = [list objectAtIndex:row];
cell.textLabel.text = rowString;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
return cell;

}

#pragma mark -
#pragma mark Table Delegate Methods
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hey, boss do you see the   disclosure button?" message:@"If you're trying to drill down, touch that instead mate!" delegate:nil cancelButtonTitle:@"Won't happen again" otherButtonTitles:nil];
[alert show];
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:   (NSIndexPath *)indexPath
{
if (childController == nil)
{
    childController = [[LWWDisclosureDetailController   alloc]initWithNibName:@"LWWDisclosureDetail" bundle:nil];
}
childController.title = @"Disclosure Button Pressed";
NSUInteger row = [indexPath row];
NSString *selectedMovie = [list objectAtIndex:row];
NSString *detailMessage = [[NSString alloc]initWithFormat:@"You pressed the disclosure  button for %@.", selectedMovie];
childController.message = detailMessage;
childController.title = selectedMovie;
[self.navigationController pushViewController:childController animated:YES];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

BV45
  • 605
  • 3
  • 10
  • 27

2 Answers2

0

Why not start the array with the VC instead of after the VC loads? Try overriding the init method.

- (id) init {
    if((self == [super init])) {
        //load your array here and set
    }
    return self;
}

That way, on older devices, you don't have to wait after the view loads to see the array. But, however, this is my preference. I love to override init methods and create my own.

Also, for some weird reason on my SDK, I have to use NSMutableArray instead of NSArray or it won't work. Maybe you have the same issue?

Also, I've noticed NSString *selectedMovie. Instead of using just "row", use the getter indexPath.row.

Hope these suggestions helped!

I am Root.
  • 131
  • 7
  • Ok, I haven't had that problem on the view loads but i'll keep that in mind in the future; thank you. How would changing how I name the row that was selected resolve the issue? It would still bring back the same value(row) correct? – BV45 Jul 29 '12 at 21:50
  • Yeah that's true. I didn't see the line above it lol. The only difference between mine and your code is that mine checks the section with an if statement and then applies the text labels if you want to try that. – I am Root. Jul 29 '12 at 22:06
0

Call:

[self.tableView reloadData]; (put in place of self.tableView the var or property connected to the tableView)

after the:

self.list = array;

code line in the viewDidLoad method

and put a

NSLog(@"number of rows: %d", [self.list count]);

in

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
     return [list count];//
  }

to check if it is not zero.

Esses77
  • 86
  • 2
  • 7
  • To see the output would I go to Product --> Generate Output? – BV45 Jul 29 '12 at 21:59
  • you can see how to do it reading http://stackoverflow.com/questions/3377309/xcode-4-how-do-you-view-the-console (a quick way is the 5th answer...) – Esses77 Jul 29 '12 at 22:01
  • Hmm..I did Command-Shift-Y to bring up the debugger but no output when I ran the build? – BV45 Jul 29 '12 at 22:17
  • I read in a wrong way :-). I cut and paste the correct answer: The console is no extra window anymore but it is under the texteditor area. You can set the preferences to always show this area. Go to "General" "Run Start" and activate "Show Debugger". Under "Run completes" the Debugger is set to hide again. You should deactivate that option. Now the console will remain visible. – Esses77 Jul 29 '12 at 22:21
  • Yes the Command-Shift-Y does the same thing to bring the debugger. But no output is coming out. Do I need to manually do something to redirect to the output screen? – BV45 Jul 29 '12 at 22:54
  • I suspect you have no connected the tableView to its outlet or set the UITableViewDelegate and UITableViewDataSource to DisclosureButtonController. – Esses77 Jul 30 '12 at 07:08
  • Ok, I'll check this and come back to it. I believe I did that and control and dragged that from the file owner. Will update on this. – BV45 Jul 30 '12 at 19:45