我正在尝试在我的 View Controller (不是 TableViewController)中嵌入 UITableView。
我无法显示我的任何数据。
以下是相关代码:
M 文件:
@interface ViewController () <CBCentralManagerDelegate, CBPeripheralDelegate, UITableViewDelegate, UITableViewDataSource>
@property (strong, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic) NSMutableArray *Device_array_name;
@end
.
.
.
- (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];
}
cell.textLabel.text=self.Device_array_name[indexPath.row];
return cell;
}
我还定义了部分和行的数量,并且我的数组确实有内容。我对 iOS 开发还很陌生,所以毫无疑问我错过了一些东西。
谢谢
最佳答案
应该为 UI 控件定义委托(delegate)和数据源,以调用它们各自的委托(delegate)。
例如:在您的 viewDidLoad
函数定义
tableView.delegate = self
tableView.datasource = self
它会起作用的。
关于ios - 用数组填充 UITableView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34389240/