ios - UITableView & Controller 给我空 TableView

标签 ios objective-c xcode

我有一个应用程序(导航 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/

相关文章:

ios - 将枚举案例与参数进行比较

objective-c - 指向整数的指针

ios - 当我在一个 UIViewController 中有两个 UITableViews 时看不到单元格

c++ - Sprite 表动画 Cocos2dx

ios - 在 TableView 未使用的空间添加 UIButton

ios - 使用 UIAccessibility 读取 HTML 选择

objective-c - 为什么我不能使用从 Objective-C 对象到 Swift 属性的 KVC?

ios - 有没有办法在消息和我的 iOS 应用程序之间进行通信?

XCode 接口(interface)构建器缺少 View 层次结构

iphone - 新的 ViewControllers 导致黑屏