Xcode 4.3.2で次のことを試しています。シングル ビュー アプリケーションを作成しました。私のViewController
道具UITableViewDelegate
、UITableViewDataSource
。
でViewController.m
:
UITableView *tv = [[UITableView alloc] initWithFrame:CGRectMake(0, 10, 120, 100)
style:UITableViewStylePlain];
tv.delegate = self;
tv.dataSource = self;
[self.view addSubview:tv];
numberOfSectionsInTableView
、numberOfRowsInSection
、cellForRowAtIndexPath
およびを実装しdidSelectRowAtIndexPath
ました。問題なく動作し、「ようこそ」が 2 行で表示されます。しかし、UITableView
作成をinitに配置すると、機能しません。
- (id)init
{
self = [super init];
if (self) {
UITableView *tv = [[UITableView alloc] initWithFrame:
CGRectMake(0, 10, 120, 100) style:UITableViewStylePlain];
tv.delegate = self;
tv.dataSource = self;
[self.view addSubview:tv];
}
return self;
}