2010-01-19 78 views
0

我在我的标签栏模板应用程序的midddle中有一个tableview ..我想添加名为'例程'的NSMutableArray的内容。TableView不能正确显示和崩溃,

这里是我的.h文件

#import <UIKit/UIKit.h> 


@interface FirstViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> { 

NSMutableArray *routines; 
} 

@property (nonatomic, retain) NSMutableArray *routines; 

- (IBAction)showNewEventViewController; 



@end 

和我的.m文件。

#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; 
} 

和viewDidLoad方法

- (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"; 


} 

我的目标只是没有显示。正如你所看到的,我已经添加了

并且我已经将它全部吸引到了IB中。

当我尝试打开我的应用程序(返回)时,它崩溃,并吐出以下日志。

[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 
) 

我不知道怎么回事,因为我有点新手。

谢谢你们!

山姆

回答

2

它看起来就像你分配你的表是你的UITabBarController,而不是你的FirstViewController对象的数据源。粘贴错误消息的第二行是说它试图获取numberOfRows,但其数据源不会实现它。仔细检查你在IB的连接。

+0

我在IB中创建了一个新的空白NSObject,并放入了该类。 这解决了崩溃。 但仍然我的对象不显示在表视图 – 2010-01-19 05:29:52

+0

啊得到它。 我也将这个新对象的视图链接到窗口框。 – 2010-01-19 05:31:24