【发布时间】:2012-04-25 22:30:02
【问题描述】:
如何在uiviewcontroller 中使用uitableview?下面是我正在尝试做的一个例子(除了这只是我故事板中的UITableview):
我发现我需要将委托和数据源添加到我的标题中:
//MyViewController.h
@interface MyViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
在我的实现文件中,我添加了所需的方法:
//MyViewController.m
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"cellForRowAtIndexPath");
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FileCell"];
NSLog(@"cellForRowAtIndexPath");
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSArray *fileListAct = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsDirectory error:nil];
cell.textLabel.text = [NSString stringWithFormat:@"%@",[fileListAct objectAtIndex:indexPath.row]];
return cell;
}
delegate、datasource 和 UITableView 都连接在我的故事板中:
我无法让 TableView 加载我告诉它的内容。它总是出现空白。为什么 TableView 不会填充我在 cellForRowAtIndexPath 方法中告诉它的内容?我在这里错过了什么?
【问题讨论】:
标签: uitableview uiviewcontroller ios objective-c uitableview uiviewcontroller