Showing data in a UITableView added as a subview
I´m trying to display a UITableView as a subview of a UIView.
When I trigger the action below, the view is shown but contain no data.
- (IBAction)youwin
{
UITableView *HSView = [[UITableView alloc] initWithFrame:CGRectMake(200,200,500,600)] ;
[self.view addSubview:HSView];
}
It looks like the code in the HSV开发者_如何学运维iew.m file is not triggerd.
The HSView.h
is imported into the main controller.
What am I missing?
Few problems in your code are :–
- You are leaking memory as the memory management calls are not balanced. You will need to release the instance you've created after adding it as a subview.
- When creating an instance of
UITableView
, you need to set thedelegate
anddataSource
properties for the it to work properly.dataSource
object is the one that provides the content and without it you will get an empty table view. - You are mentioning
HSView.h
so I am thinkingHSView
is a class. In that caseUITableView *HSView
is incorrect. If you wanted to instantiateHSView
then doHSView * hsView = ...
. If it is a subclass ofUITableView
, point 2 will hold for it too.
精彩评论