어떤 범주를 선택했는지에 따라 다른 하위보기가있는 셀을 갖게 될 것입니다. 새로운 카테고리를 선택하고 데이터 등을 새로 고치지 만, 다른 하위 뷰가있는 새 셀을 표시하는 대신 뷰를 다른 카테고리로 전환 할 때보기가 서로 놓이게됩니다. 어떻게 수정합니까? 여기 내 코드는 다음과 같습니다 또한셀에 다른보기를 넣으려면 UITableView의 셀을 지우십시오.
//cell for row at indexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
}
if ([currentCategory isEqualToString:@"Projects"])
{
Project *pr=[projectsArray objectAtIndex:indexPath.row];
NSLog(@"Project ID %i, ProjectName %@", pr.ident, pr.projectName);
UILabel *nameLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 20, 200, 100)];
nameLabel.text=pr.projectName;
UIImageView *iv=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 192)];
iv.image=pr.baseImage;
[cell addSubview:iv];
[cell addSubview:nameLabel];
}
else if ([currentCategory isEqualToString:@"Glossaire"])
{
Glossaire *gl=[glossaireArray objectAtIndex:indexPath.row];
UILabel *nameLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 45)];
nameLabel.font=[UIFont fontWithName:@"Arial" size:25.0f];
nameLabel.text=gl.glossaireName;
nameLabel.backgroundColor=[UIColor redColor];
UILabel *introLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 50, 200, 50)];
introLabel.font=[UIFont fontWithName:@"Arial" size:16.0f];
introLabel.text=gl.intro;
introLabel.backgroundColor=[UIColor redColor];
UILabel *descriptionLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 100, 350, 100)];
descriptionLabel.font=[UIFont fontWithName:@"Arial" size:16.0f];
descriptionLabel.text=gl.description;
descriptionLabel.backgroundColor=[UIColor redColor];
NSLog(@"Glossaire ID: %i, NAME: %@ INTRO: %@ Description %@", gl.ident, gl.glossaireName, gl.intro, gl.description);
[cell addSubview:nameLabel];
[cell addSubview:introLabel];
[cell addSubview:descriptionLabel];
}
return cell;
}
//And switching between categories
- (IBAction)viewProjects:(id)sender
{
[email protected]"Projects";
projectsArray=[dbm fetchProjectsSummary];
[mainTable reloadData];
}
- (IBAction)viewGlossaire:(id)sender
{
[email protected]"Glossaire";
glossaireArray=[dbm fetchGlossaireSummary];
[mainTable reloadData];
}
들이 재사용 식별자가되지 않습니다 말, 그것의 새로운 버전은 무엇입니까? 감사!
질문을 편집하고 제공된 코드의 형식을 지정하십시오. –
IB로 세포를 만드십니까? 그렇다면 두 개의 사용자 정의 유형의 셀을 작성하여 'currentCategory'에 따라 올바른 유형의 셀을 리턴 할 수 있습니다. 'UITableViewCell'을 서브 클래스 화하고 UI 요소를 프로그램 적으로 추가하여 동일한 작업을 수행 할 수 있습니다. –
알아, 고마워)하지만 난 이미 내 접근 방식을 선택했습니다) 덕분에 –