UITableView作为子视图? [英] UITableView as a subview?
本文介绍了UITableView作为子视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能吗?我只想在我当前的视图中找到一张小桌子......这就是我要做的事情:
Is this possible? I just want a small table in my current view... here is what I'm trying to do:
.h文件
#import <UIKit/UIKit.h>
@interface IngredientsRootView : UIViewController <UITableViewDelegate, UITableViewDataSource> {
UITableView *ingredientsTable;
}
@property (nonatomic, retain) UITableView *ingredientsTable;
@end
.m文件我有委托和数据源方法此代码:
.m file I have delegate and data source methods and this code:
ingredientsTable = [[UITableView alloc] initWithFrame:CGRectMake(10, 10, 300, 300) style:UITableViewStylePlain];
[ingredientsTable setDelegate:self];
[ingredientsTable setDataSource:self];
[self.view addSubview:ingredientsTable];
该应用程序不会崩溃,但它不显示表格。目前我只是按照以下方式设置了所有内容:
The app doesn't crash, but it doesn't show a table. At the moment I have just set everything definitely as per:
#pragma mark -
#pragma mark Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 10;
}
// the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = @"Hello";
return cell;
}
我做错了什么?谢谢
推荐答案
添加后,在表格视图上尝试调用 -reloadData
作为子视图。
Try calling -reloadData
on the table view after adding it as a subview.
此外,视图是如何设置的?它是在XIB中创建还是通过 -loadView
?
Also, how is the view set up? Is it created in a XIB or via -loadView
?
这篇关于UITableView作为子视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文