下面是一个代码并且朝向结束,我试图找出计算部分行数的方法
NS对象定义
//DataDefinition.h
#import
@interface DataDefinition : NSObject
@property (nonatomic, retain) NSString *dataHeader;
@property (nonatomic, retain) NSMutableArray *dataDetails;
@end
显示标题部分 //DataDisplay.h #import
#import "DataDefinition.h"
@interface DataDisplay : UITableViewController
@property (read write) NSInteger RowsCount;
@property (strong, nonatomic) NSMutableArray *dataSet;
@property (strong, atomic) DataDefinition *individualData;
@end
展示实施部分
//DataDisplay.m
@interface DataDisplay ()
@end
@implementation DataDisplay
@synthesize RowsCount;
@synthesize dataSet;
@synthesize individualData;
- (void)viewDidLoad
{
[super viewDidLoad];
individualData.dataHeader = @"Header1";
individualData.dataDetails = [[NSMutableArray alloc] initWithObjects:@"Header1-Detail1", @"Header1-Detail2", @"Header1-Detail3", nil];
RowsCount = [individualData.dataDetails count];
[dataSet addObject:individualData];
.
.
.
[dataSet addObject:individualData];
self.title = @"DataDisplay";
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [dataSet count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in sections.
return ?????
}
答案 0 :(得分:0)
首先,如果您要显示的数据集中没有部分,则不必实现此方法。您需要将数据存储在NSMutableArray中,该NSMutableArray将是一个数组数组:这将基本上存储每个部分的内容。
然后,您可以想象通过这种方式访问每个部分的项目数量:
[[self.yourarray objectAtIndex:section] count];
修改强>
根据您的源代码和讨论,我们的代码应该是:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in sections.
return [((DataDefinition*)[self.dataSet objectAtIndex:section]).dataDetails count]
}