我有一个应用程序(导航 Controller ),其中第二个 Controller 是 TableView Controller 。我能够通过 segue 发送我需要的数据,但无法以编程方式更新 TableView 中的条目。
我是 IOS 新手。
这是我的头文件
#import <UIKit/UIKit.h>
@interface HCIResultListViewController : UITableViewController
@property (strong,nonatomic) NSMutableDictionary *resultList;
@property (strong, nonatomic) IBOutlet UITableView *tableListView;
@end
这是我的实现文件。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 0;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"HelloCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"Hello";
// Configure the cell...
return cell;
}
谁能告诉我如何使用 tableview 和 Controller ?
我确实看过几个文档和示例,但真的无法理解
最佳答案
您需要为 TableView 指定行数和节数。像这样。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
// Return the number of rows in the section.
return [sourceData Count]//i.e., 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"HelloCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = @"Hello";
// Configure the cell...
return cell;
}
关于ios - UITableView & Controller 给我空 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15245012/