How do I find numberOfRowsInSection for dataset of objects

Below is a code and towards end, I am trying to figure out the method to count the number of rows in section

The NS Object Definition //DataDefinition.h #import

@interface DataDefinition : NSObject
@property (nonatomic, retain) NSString *dataHeader;
@property (nonatomic, retain) NSMutableArray *dataDetails;

@end

The Display header section //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

The Display implementation section

//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 ?????
} 

Answers


First if you don't have section in the dataset you want to display you don't have to implement this method. You need otherwise to store your data in an NSMutableArray which will be an array of array: this will basically store your content per section.

You can then imagine access to your number of items per section this way:

[[self.yourarray objectAtIndex:section] count];

EDIT

According to your source code and from the discussion we have your code should be:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in sections.
    return [((DataDefinition*)[self.dataSet objectAtIndex:section]).dataDetails count] 
} 

Need Your Help

Cloud-based testing automation tools

selenium testing automated-tests regression-testing

I try to find a service which provides a functionality that allow me to create manual tests autmation for web-based applications in simple way with visual constructor without any coding, so it coul...

how to make mass assignment

java

How can i make mass asssignment for stack of variables?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.