Adım 1: Bölüm başlığının boyutunu ayarlayın. Aşağıdaki gibi örnek.
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 55;
}
Adım 2: & dönüş özel bölüm başlığı oluşturur.
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *aView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 55)];
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 320, 55)];
[btn setTag:section+1];
[aView addSubview:btn];
[btn addTarget:self action:@selector(sectionTapped:) forControlEvents:UIControlEventTouchDown];
return aView;
}
Adım 3: bölme dönüş sayısı. (Burada örneğin 10)
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 10;
}
Adım 4: Bölüm başına satır sayısı. (Örneğin, her bölüm için 4 sıra)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 4;
}
Adım 5: işlemek için olay ekleyin: (her satır için UITableViewCell) & dönüş hücre
- (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];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text=[NSString stringWithFormat:@"%i_%i",indexPath.section,indexPath.row];
return cell;
}
Adım 6 oluşturmak TouchDown bölüm üstbilgisinde.
- (void)sectionTapped:(UIButton*)btn {
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:btn.tag-1] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
co0o0ol yanıtı için teşekkürler, gerçekten gerçekten benim için çalışır .. :-) –