【问题标题】:TableView not displaying correctly and crashing,TableView 无法正确显示并崩溃,
【发布时间】:2010-01-19 05:13:01
【问题描述】:

我的标签栏模板应用程序中间有一个表格视图。 我想添加名为“routines”的 NSMutableArray 的内容。

这是我的 .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 中。

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

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

我不知道出了什么问题,因为我有点新手。

谢谢各位!

山姆

【问题讨论】:

    标签: iphone uitableview crash


    【解决方案1】:

    看起来您已将表的数据源分配为您的 UITabBarController,而不是您的 FirstViewController 对象。您粘贴的错误消息的第二行是说它正在尝试获取 numberOfRows,但它的数据源没有实现它。仔细检查您在 IB 中的连接。

    【讨论】:

    • 我在 IB 中创建了一个新的空白 NSObject,并放入课堂。这解决了崩溃。但是我的对象仍然没有显示在表格视图中
    • 啊,明白了。我还将这个新对象的视图链接到窗口框。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-08
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    • 1970-01-01
    • 2012-07-04
    • 2016-02-20
    相关资源
    最近更新 更多