TableViewで奇妙な問題が発生しています。すべてを明確にするためのコードを次に示します。
私はタブ付きペインを使用していますが、これは私の2つのViewControllerの1つにすぎません。
ご覧のとおり、私が行うのは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に実装されている関数の1つにブレークポイントを設定しても何も呼び出されないので、デリゲートとsourceDataが間違ったクラスを指していると想定していますか?ただし、テーブルをビューに配置する前に、それらを明示的に割り当てます。
UIStandort * Standortは、プロパティが保持され、これが役立つ場合は非アトミックで宣言されます。
#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
ありがとう。