我该如何在UIViewController中使用UITableview?下面是我尝试做的事情的示例(除了这只是我故事板中的
在我的实现文件中,我已经添加了所需的方法:
在我的Storyboard中,
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;
}
在我的Storyboard中,
delegate
、datasource
和UITableView
都已连接。