我正在开发一个带有 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/