开发者

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 :–

  1. 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.
  2. When creating an instance of UITableView, you need to set the delegate and dataSource 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.
  3. You are mentioning HSView.h so I am thinking HSView is a class. In that case UITableView *HSView is incorrect. If you wanted to instantiate HSView then do HSView * hsView = .... If it is a subclass of UITableView, point 2 will hold for it too.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜