views:

23

answers:

1

Hi,

I have a tableview in the midddle of my tab bar template application.. I wanted to add the contents of the NSMutableArray called 'routines'.

Here is my .h file

#import <UIKit/UIKit.h>


@interface FirstViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {

NSMutableArray *routines;
}

@property (nonatomic, retain) NSMutableArray *routines;

- (IBAction)showNewEventViewController;   



@end

and my .m file.

#import "FirstViewController.h"
#import "NewEventViewController.h"

@implementation FirstViewController

@synthesize routines;



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

return [routines count];

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

// Set up the cell...
NSString *cellValue = [routines objectAtIndex:indexPath.row];
[cell.textLabel setText:cellValue];

return cell;
}

and viewDidLoad method

- (void)viewDidLoad {

routines = [[NSMutableArray alloc] init];

[routines addObject:@"Hello"];
[routines addObject:@"Temp"];
[routines addObject:@"Temp2"];
[routines addObject:@"Temp3"];
[routines addObject:@"Temp4"];
self.navigationItem.title = @"test";


}

My objects are just not displaying. As you can see, i have Added

and i have hooked it all up in IB correctly.

When I try to open my app ( return) it crashes, and spits out the following log.

 [Session started at 2010-01-19 17:57:01 +1300.]
2010-01-19 17:57:03.563 Gym Buddy[12690:207] *** -[UITabBarController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x3b12450
2010-01-19 17:57:03.564 Gym Buddy[12690:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UITabBarController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x3b12450'
2010-01-19 17:57:03.577 Gym Buddy[12690:207] Stack: (
29295707,
2538743049,
29677627,
29247094,
29099714,
4364410,
4371786,
4370783,
3087322,
3027833,
3069268,
3057823,
55808688,
55808111,
55806150,
55805242,
2731769,
2755464,
2737875,
2764981,
37392081,
29080448,
29076552,
2731625,
2768899,
9784,
9638
)

I have no idea what is going wrong, since im a bit of a newbie.

Thanks Guys!

Sam

+2  A: 

It looks like you've assigned the datasource of your table to be your UITabBarController, rather than your FirstViewController object. That second line of your pasted error message is saying it's trying to get the numberOfRows, but its datasource doesn't implement it. Double check your connections in IB.

Ben Gottlieb
i created a new blank NSObject in IB, and put in the class. That solved the crash. But still my objects are not displaying in the table view
Sam Jarman
ah got it. I also linked the view of this new object, to the window box.
Sam Jarman