TableView不会显示提供的数据

时间:2012-09-23 22:02:17

标签: iphone ios uitableview

我对TableView有一个奇怪的问题。以下是一些澄清所有内容的代码:

我正在使用选项卡式窗格,这就是我的两个ViewControllers之一:

正如您所看到的,我所做的就是设置一个UIView并将tableView放在它的正上方。

#import "SuchenCtrl.h"

@interface SuchenCtrl ()

@end

@implementation SuchenCtrl

@synthesize MainView;
@synthesize Standort;

- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view.
    self.view = self.MainView;

    [self.Standort.tableView setDelegate:self.Standort];
    [self.Standort.tableView setDataSource:self.Standort];

    [self.MainView addSubview:self.Standort.tableView];
}

- (id)init {
    self = [super init];

    if(self) {
        CGRect rect = [[UIScreen mainScreen] applicationFrame];
        self.MainView = [[UIView alloc] initWithFrame:rect];
        [self.MainView setBackgroundColor:[UIColor blackColor]];

        //Alloc UITableViewController
        self.Standort = [[UIStandort alloc] initWithStyle:UITableViewStylePlain];

        [self.Standort release];
        [self.MainView release];
    }

    return self;
}

@end

现在UIStandort是另一个简单地继承自UITableViewController的类。它实现了显示数据所需的所有功能。我试图实现的只是表格显示“测试”几次,但它不会。该表很好地显示,但只有空单元格。当我断开UIStandort类中的一个实现函数时,没有任何东西被调用,所以我的假设是委托和sourceData指向错误的类?但是,在将表放在视图上之前,我明确地指定了这些。

UIStandort *如果有帮助,声明Standort属性为retain和nonatomic。

#import "UIStandort.h"

@interface UIStandort ()

@end

@implementation UIStandort

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 5;
}

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

    UITableViewCell* cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    cell.textLabel.text = @"Test";

    [cell autorelease];

    return cell;
}

@end

感谢。

1 个答案:

答案 0 :(得分:3)

对于节中的行数,返回0。文档说明:

  

tableView中的节数。默认值为1.

你可以尝试:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}
相关问题