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 thedelegateanddataSourceproperties for the it to work properly.dataSourceobject is the one that provides the content and without it you will get an empty table view. - You are mentioning
HSView.hso I am thinkingHSViewis a class. In that caseUITableView *HSViewis incorrect. If you wanted to instantiateHSViewthen doHSView * hsView = .... If it is a subclass ofUITableView, point 2 will hold for it too.
加载中,请稍侯......
精彩评论