ios - 包含 3 个组的合适 View

标签 ios objective-c uitableview

我正在开发一个带有 View Controller 和 TableView 的 ios 应用程序。我正在尝试加载 3 组的项目列表,但是当我编译它时它显示正确的计数但没有显示所有项目只是重复项目。请帮忙。让我在这里发布我的代码。

@interface ViewController ()

@end

@implementation ViewController {
    NSArray *menuItems;
    NSArray *menuItems2;
    NSArray *dash;

}

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithWhite:0.6f alpha:1.0f];
    self.tableView.backgroundColor = [UIColor colorWithWhite:0.6f alpha:1.0f];
    self.tableView.separatorColor = [UIColor colorWithWhite:0.15f alpha:0.2f];
    menuItems = @[@"itm1", @"itm2", @"itm3", @"itm4"];
    menuItems2 = @[@"itm1", @"itm2", @"itm3", @"itm4"];
    dash = @[@"itm1", @"itm2"];
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    if (section == 0) {
        return [menuItems count];
    }
    if (section == 1) {
        return [menuItems2 count];
    }
    if (section == 2) {
        return [dash count];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    return cell;
}

@end

最佳答案

需要编写您的 cellForRowAtIndexPath... 方法,以便根据单元格的部分和行用适当的数据填充单元格。现在你除了使用一个空单元格什么都不做。

关于ios - 包含 3 个组的合适 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22536897/

相关文章:

android - 在 react-native 中运行预构建脚本

iphone - iPhone 上的色彩平衡

iphone - 如何在 UIImageView 上设置 UIGestureRecognizer?

ios - Xcode 8 "the aps-environment entitlement is missing from the app' s signature"on submit

ios - 动画完成后是否需要删除 CABasicAnimation?

ios - 如何更改 objective-c 中的文本字段边框样式?

image - TableView 和图像圈

swift - 更新核心数据对象顺序 - 不工作

ios - 如何快速调用从一个类到另一个类的 tableview 委托(delegate)方法?

ios - 在 block 中推送 View