加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – UITableView&Controller为我提供了空表视图

发布时间:2020-12-14 17:12:05 所属栏目:百科 来源:网络整理
导读:我有一个应用程序(导航控制器),其中第二个控制器是一个表视图控制器.我能够通过segue发送我所需的数据,但无法以编程方式更新tableview中的条目. 我是IOS的新手. 这是我的头文件 #import UIKit/UIKit.h@interface HCIResultListViewController : UITableViewC
我有一个应用程序(导航控制器),其中第二个控制器是一个表视图控制器.我能够通过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&控制器?

我确实经历了几个文档和示例,但实际上无法理解

解决方法

您需要指定表视图的行和节数.像这样.

- (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;
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读