Tom*_*ulz 1 iphone cocoa-touch uitableview
我的热切梦想是以编程方式确定具有不同行大小的UITableView.我已经阅读了UITableViewDataSource文档,并实现了这些方法:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
Run Code Online (Sandbox Code Playgroud)
我们可以在这里看到:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return (CGFloat) 200.0f;
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* test = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil ];
test.textLabel.text = @"TEST";
CGRect ffframe = test.frame;
ffframe.size.height *= 200.0f;
test.frame = ffframe;
return test;
}
Run Code Online (Sandbox Code Playgroud)
这些只是试图制作一个简单的表,一行,高度为200.0.我尝试在委托方法中返回高度,并明确设置它.两者都不起作用.
我尝试在调试器中捕获heightForRow方法,似乎永远不会被调用.
我的表行始终是我在界面构建器中设置的大小.
我有数据源连接正确,否则它不会得到行和textLabel正确.
这是一个委托方法,所以请确保您拥有
self.tableview.delegate = self;
Run Code Online (Sandbox Code Playgroud)
在viewDidLoad中,或者将xib中的tableview委托属性链接到控制器.
| 归档时间: |
|
| 查看次数: |
2484 次 |
| 最近记录: |