1
我有一个奇怪的问题与TableView。下面是一些代码来澄清一切: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
谢谢。
哈哈,这并获得成功。谢谢,这个问题解决了。 – user1692986
@ user1692986太棒了!如果您想将其标记为已解决,那么将从队列中清除它。 – FluffulousChimp