【发布时间】:2014-01-10 21:59:31
【问题描述】:
我进行了一些广泛的研究,并意识到使用普通 UITableViewController 时的陷阱。我还发现了类似的questions,但没有任何运气。我一定错过了一些非常琐碎的事情。
我已经在 Github 上上传了test project。
我的目标是将 UITableView 放在 UIView 中。
我有一个 xibfile 并将文件的所有者设置为我的视图控制器,并将所有内容连接起来。
@interface TNViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
这就是视图控制器的实现方式。
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:@"TNViewController" bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 3;
}
- (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];
}
return cell;
}
在 App 委托中我是这样运行的:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
TNViewController *vc = [TNViewController new];
[[self window] setRootViewController:vc];
...
}
但是,表格仍然是空的,cellForRowAtIndexPath 永远不会被击中。一定和包裹表格的 UIView 有关,但我不确定我接线错了什么。
【问题讨论】:
标签: ios uitableview uiview ios7