- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return [self.LoadFile count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 4;
}
int title =0;
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
for (title = 0 ; title <= section; title++)
{
NSLog(@"section - %d ",title);
NSDictionary *dict = [LoadFile objectAtIndex:title];
NSString *titlename = [[NSString alloc]initWithFormat:@"%@",[dict valueForKey:@"name"]];
NSLog(@"%@",titlename);
if (section == title)
return titlename;
}
}
這裏我使用的是在網頁上創建了兩個數組,在這種情況下,它會正常工作,但對於情況下,我需要從DB來填充,然後我應該怎麼辦的數據。在iphone填充動態
- (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] autorelease];
while (i < sec)
{
dict = [LoadFile objectAtIndex:0];
NSString *addr = [[NSString alloc]initWithFormat:@"%@",[dict valueForKey:@"address"]];
NSString *con = [[NSString alloc]initWithFormat:@"%@",[dict valueForKey:@"contact"]];
NSString *sal = [[NSString alloc]initWithFormat:@"%@",[dict valueForKey:@"salary"]];
NSString *tec = [[NSString alloc]initWithFormat:@"%@",[dict valueForKey:@"tech"]];
NSArray *arr = [[NSArray alloc] initWithObjects:addr,con,sal,tec,nil];
// NSArray *arr = [[NSArray alloc] initWithObjects:i,i,i,i,nil];
//NSArray *arr2 = [[NSArray alloc] initWithObjects:@"12",@"22",@"32",@"42",nil];
NSLog(@"%@",arr);
if(indexPath.section == i)
{
cell.textLabel.text = [arr objectAtIndex:indexPath.row];
i++;
}
}
return cell;
}
for (i = 0 ; i <= sec-1; i++)
{
NSLog(@"section - %d ",title);
NSDictionary *dict = [LoadFile objectAtIndex:title];
if (indexPath.section == 0)
{
UILabel *Address = [[UILabel alloc]initWithFrame:CGRectMake(1,9, 200, 20)];
Address.textColor = [UIColor blueColor];
Address.backgroundColor = [UIColor clearColor];
[Address setFont:[UIFont boldSystemFontOfSize:14.0]];
[Address setTag:i];
Address.text = [dict objectForKey:@"address"];
[cell.contentView addSubview:Address];
UILabel *tech = [[UILabel alloc]initWithFrame:CGRectMake(1,9, 200, 20)];
tech.textColor = [UIColor blueColor];
tech.backgroundColor = [UIColor clearColor];
[tech setFont:[UIFont boldSystemFontOfSize:14.0]];
[tech setTag:i];
tech.text = [dict objectForKey:@"tech"];
[cell.contentView addSubview:tech];
}
else if (indexPath.section == 1)
{
UILabel *tech = [[UILabel alloc]initWithFrame:CGRectMake(1,9, 200, 20)];
tech.textColor = [UIColor blueColor];
tech.backgroundColor = [UIColor clearColor];
[tech setFont:[UIFont boldSystemFontOfSize:14.0]];
[tech setTag:i];
tech.text = [dict objectForKey:@"tech"];
[cell.contentView addSubview:tech];
}
}
else if (indexPath.section == 0)
{
UILabel *contact = [[UILabel alloc]initWithFrame:CGRectMake(1,9, 200, 20)];
contact.textColor = [UIColor blueColor];
contact.backgroundColor = [UIColor clearColor];
[contact setFont:[UIFont boldSystemFontOfSize:14.0]];
contact.text = [dict objectForKey:@"contact"];
// NSLog(@"Val-%@",[dict objectForKey:@"name"]);
[contact setTag:-4];
[cell.contentView addSubview:contact];
}
else if (indexPath.section == 0)
{
UILabel *salary = [[UILabel alloc]initWithFrame:CGRectMake(1,9, 200, 20)];
salary.textColor = [UIColor blueColor];
salary.backgroundColor = [UIColor clearColor];
[salary setFont:[UIFont boldSystemFontOfSize:14.0]];
salary.text = [dict objectForKey:@"salary"];
// NSLog(@"Val-%@",[dict objectForKey:@"name"]);
[salary setTag:-4];
[cell.contentView addSubview:salary];
}
else
{
UILabel *tech = [[UILabel alloc]initWithFrame:CGRectMake(1,9, 200, 20)];
tech.textColor = [UIColor blueColor];
tech.backgroundColor = [UIColor clearColor];
[tech setFont:[UIFont boldSystemFontOfSize:14.0]];
tech.text = [dict objectForKey:@"tech"];
// NSLog(@"Val-%@",[dict objectForKey:@"name"]);
[tech setTag:-4];
[cell.contentView addSubview:tech];
}
我想一旦你的陣列已經用新的數據更新,從數據庫表中填充數據,動態
你是什麼意思「從數據庫填充」? – dbrajkovic 2012-02-24 05:22:18
你想做什麼?... – EmilioPelaez 2012-02-24 05:23:14
其實我想從sqllite db中獲取信息並在grouprd風格的tableview中顯示它。編號數據庫中的記錄可以動態更改。所以我怎麼能顯示數據的單元格中的一行特別section.Hope你明白我可能說 – Mania 2012-02-24 05:27:27