使用Array填充UITableView不起作用

Van*_*ard 1 objective-c uitableview ios

我试图在我的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
Run Code Online (Sandbox Code Playgroud)

...

- (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;
}
Run Code Online (Sandbox Code Playgroud)

我还定义了部分和行的数量,我的数组确实有内容.我对iOS开发很陌生,所以我毫无疑问会遗漏一些东西.

谢谢

Zum*_*med 6

应为UI控件定义委托和数据源,以便为其各自的委托调用.

对于实例:在您的viewDidLoad函数中定义

tableView.delegate = self
tableView.datasource = self
Run Code Online (Sandbox Code Playgroud)

它会工作.