ios - 用数组填充 UITableView 不起作用

标签 ios objective-c uitableview

我正在尝试在我的 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/

相关文章:

objective-c - 如何从 iphone 应用程序共享链接?

ios - 如何使用 UITableViews 通过 Swift 创建静态和动态行

ios - 在 UITabBarController View 之间共享变量

ios - 蓝牙输入到内置扬声器iOS 7

objective-c - objective-c : making point Larger through long press

ios - 小部件在表格 View swift ios的单元格中相互重叠

swift - 如何根据不同的条件在单个表格 View 中以不同的方式使用相同的自定义单元格?

ios - AWSCognitoIdentityMultiFactorAuthentication 永远不会返回

ios - 创建具有默认行为的更可重用的 UITableView 子类

objective-c - 使用带缩放功能的 UIWebView 显示 Google map