Reputation: 6534
i want a titleHeaderForInSection but i'm doing something wrong my code:
self.List = [[NSArray alloc]
initWithObjects:
@"2",
nil];
self.List2 = [[NSArray alloc]
initWithObjects:
@"1",
nil];
and;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
// Configure the cell...
cell.textLabel.text = [self.List objectAtIndex:[indexPath row]];
cell.textLabel.text = [self.List2 objectAtIndex:[indexPath row]];
}
return cell;
}
Is something like this possible? It's now showing me only '1'
cell.textLabel.text = [self.List objectAtIndex:[indexPath row]];
cell.textLabel.text = [self.List2 objectAtIndex:[indexPath row]];
A screenshot:
![enter image description here][1]
The problem is that under TitleHeaderForSection 'A' i want '2' and under TitleHeaderForSection 'B' i want the number 1
https://i.sstatic.net/9uD2Q.png
Edit:
i'm using the code but a strange thing i have;
self.List = [[NSArray alloc]
initWithObjects:
@"1",
@"2",
@"3",
@"4",
nil];
self.List2 = [[NSArray alloc]
initWithObjects:
@"5",
@"6",
@"7",
@"8",
nil];
self.List3 = [[NSArray alloc]
initWithObjects:
@"9",
@"10",
@"11",
@"12",
nil];
self.List4 = [[NSArray alloc]
initWithObjects:
@"13",
@"14",
@"15",
@"16",
nil];
and:
if(indexPath.section == 0)
{
cell.textLabel.text = [self.List objectAtIndex:[indexPath row]];
}
else if (indexPath.section == 1)
{
cell.textLabel.text = [self.List2 objectAtIndex:[indexPath row]];
}
else if (indexPath.section == 2)
{
cell.textLabel.text = [self.List3 objectAtIndex:[indexPath row]];
}
else if (indexPath.section == 4)
{
cell.textLabel.text = [self.List4 objectAtIndex:[indexPath row]];
}
//
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
switch (section) {
case 0:
return [self.List count];
case 1:
return [self.List2 count];
case 2:
return [self.List3 count];
case 3:
return [self.List4 count];
default:
return 0;
}
}
But after TitleHeaderForSection 'B' this is wat happend instead of 9/10/11/12 and under D 13/14/15/16 it's showing:
https://i.sstatic.net/LuYOx.png
Upvotes: 0
Views: 51
Reputation: 21805
you are messing this up
do this
if(indexPath.section == 0)
{
cell.textLabel.text = [self.List objectAtIndex:[indexPath.row]];
}
else
{
cell.textLabel.text = [self.List2 objectAtIndex:[indexPath.row]];
}
Right now you first assign the value 2 in line
cell.textLabel.text = [self.List objectAtIndex:[indexPath row]];
and then 1
in this line
cell.textLabel.text = [self.List2 objectAtIndex:[indexPath row]];
So in the end you always get 1.
Upvotes: 1