Reputation: 67
How can I manage different no of the rows in different no of sections ? no of rows & sections are not fixed depends on another table view in other class.Suppose If xxx section Header then it contains 5 rows ,another section header contain 4 rows. section header is the account title in table view from other class
Upvotes: 1
Views: 1874
Reputation: 266
Try this
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section == 0){
return 5;
}
if (section == 1){
return 10;
}
//etc.
}
Upvotes: 0
Reputation: 720
Its Really Simple , Use below tableView delegates-
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// return your another table view's array count here, on which no of sections depends.
}
// Customize the number of rows in the table view.
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// use like this
int noOfRows = 0;
if(section == 0)
{
noOfRows = x;
}
else if(section ==1)
{
noOfRows = y;
}
.
.
.
else
{
noOfRows = z;
}
return noOfRows;
}
x, y, z are NSInteger here
Upvotes: 0
Reputation: 821
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 3; or [yourarray count] // 3 sections 0,1,2
}
For different numver of rows in diffrent sections
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the sections.
if( section == 0) // first section with 5 rows
return [[yourarray objectAtIndex:section] count];
if( section == 1) // 2nd section with 4 rows
return [[yourarray objectAtIndex:section] count];
if( section == 2) // 3rd section with 57rows
return [[yourarray objectAtIndex:section] count];
}
Upvotes: 2
Reputation: 688
Hope it helps:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if( section == 0)
return [array count];
if( section == 1)
return [array2 count];
if( section == 2)
return [array3 count];
}
Upvotes: 1
Reputation: 814
In table view delegate method; it has:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return data.count;
}
and
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [data objectAtIndex:section].count;
}
You can set your sections number and rows number in those two methods.
Of course you have to also configure your data to two dimension array.
Upvotes: 1