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

前端之家收集整理的这篇文章主要介绍了ios – UITableView&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&控制器?

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

解决方法

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

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

猜你在找的Xcode相关文章