2011-02-28 2 views
0

테이블 프로그래밍 동안 :문제 난 그룹화 된 테이블이 있고, 내가 작성하는 경우

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     if (indexPath.row == 7){ 

그것은 7 행을 클릭하지 않습니다 ...

을 나는이 있습니다 종류의 UITableView (그룹화 됨) :

- (void)viewDidLoad { 
    NSArray *arrTemp1 = [[NSArray alloc] 
         initWithObjects:@"Scuola/Università",@"Uscita con le amiche",@"Pranzo di lavoro",@"Lavoro",@"Appuntamento",@"All'ultimo momento",nil]; 
    NSArray *arrTemp2 = [[NSArray alloc] 
         initWithObjects:@"Cena con amici",@"Cena di lavoro",@"Pub/Discoteca",@"Festa elegante",@"Appuntamento",@"All'ultimo momento",nil]; 
    NSArray *arrTemp3 = [[NSArray alloc] 
         initWithObjects:@"Compleanno",@"Anniversario",@"Matrimonio",@"Laurea/Promozione",@"San Valentino",@"Natale/Capodanno",nil]; 
    NSArray *arrTemp4 = [[NSArray alloc] 
         initWithObjects:@"Scelta e uso fondotinta",@"Scelta dei colori",@"I pennelli",@"Come sfumare",@"Contouring",@"Labbra perfette",nil]; 
    NSDictionary *temp =[[NSDictionary alloc] 
         initWithObjectsAndKeys:arrTemp1,@"Trucco da giorno",arrTemp2, 
         @"Trucco da sera",arrTemp3,@"Eventi speciali",arrTemp4,@"Lezioni di base",nil]; 
    self.tableContents =temp; 
    [temp release]; 
    self.sortedKeys =[[self.tableContents allKeys] 
         sortedArrayUsingSelector:@selector(compare:)]; 
    [arrTemp1 release]; 
    [arrTemp2 release]; 
    [arrTemp3 release]; 
    [arrTemp4 release]; 
    [super viewDidLoad]; 
} 

== 7과 다른 값이 필요합니까?

은 사전에 감사

전체 코드 :

#import "TabellaController.h" 

@implementation TabellaController 
@synthesize tableContents; 
@synthesize sortedKeys; 



- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath { 
    return UITableViewCellAccessoryDisclosureIndicator; 
} 

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 
- (void)viewDidLoad { 
    NSArray *arrTemp1 = [[NSArray alloc] 
         initWithObjects:@"Scuola/Università",@"Uscita con le amiche",@"Pranzo di lavoro",@"Lavoro",@"Appuntamento",@"All'ultimo momento",nil]; 
    NSArray *arrTemp2 = [[NSArray alloc] 
         initWithObjects:@"Cena con amici",@"Cena di lavoro",@"Pub/Discoteca",@"Festa elegante",@"Appuntamento",@"All'ultimo momento",nil]; 
    NSArray *arrTemp3 = [[NSArray alloc] 
         initWithObjects:@"Compleanno",@"Anniversario",@"Matrimonio",@"Laurea/Promozione",@"San Valentino",@"Natale/Capodanno",nil]; 
    NSArray *arrTemp4 = [[NSArray alloc] 
         initWithObjects:@"Scelta e uso fondotinta",@"Scelta dei colori",@"I pennelli",@"Come sfumare",@"Contouring",@"Labbra perfette",nil]; 
    NSDictionary *temp =[[NSDictionary alloc] 
         initWithObjectsAndKeys:arrTemp1,@"Trucco da giorno",arrTemp2, 
         @"Trucco da sera",arrTemp3,@"Eventi speciali",arrTemp4,@"Lezioni di base",nil]; 
    self.tableContents =temp; 
    [temp release]; 
    self.sortedKeys =[[self.tableContents allKeys] 
         sortedArrayUsingSelector:@selector(compare:)]; 
    [arrTemp1 release]; 
    [arrTemp2 release]; 
    [arrTemp3 release]; 
    [arrTemp4 release]; 
    [super viewDidLoad]; 
} 

- (void)dealloc { 
    [tableContents release]; 
    [sortedKeys release]; 
    [super dealloc]; 
} 

#pragma mark Table Methods 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ 
    return [self.sortedKeys count]; 
} 

- (NSString *)tableView:(UITableView *)tableView 
titleForHeaderInSection:(NSInteger)section 
{ 
    return [self.sortedKeys objectAtIndex:section]; 
} 

- (NSInteger)tableView:(UITableView *)table 
numberOfRowsInSection:(NSInteger)section { 
    NSArray *listData =[self.tableContents objectForKey: 
         [self.sortedKeys objectAtIndex:section]]; 
    return [listData count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; 

    NSArray *listData =[self.tableContents objectForKey: 
         [self.sortedKeys objectAtIndex:[indexPath section]]]; 

    UITableViewCell * cell = [tableView 
           dequeueReusableCellWithIdentifier: SimpleTableIdentifier]; 

    if (cell == nil){ cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero 
                reuseIdentifier:@"cellID"] autorelease]; 
    } 

//inseriamo nella cello l'elemento della lista corrispondente 
cell.textLabel.text = [listData objectAtIndex:indexPath.row]; 

return cell; 
    } 


    // Metodo relativo alla selezione di una cella 
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     if (indexPath.row == 6){ 
      //l'utente ha cliccato sull'elemeno iPhone, quindi carichiamo la vista relativa 
      detail = [[ScuolaUniversitaController alloc] initWithNibName:@"ScuolaUniversita" bundle:[NSBundle mainBundle]]; 
     } 

     //Facciamo visualizzare la vista con i dettagli 
     [self.navigationController pushViewController:detail animated:YES]; //rilasciamo il controller 
     [detail release]; 
     detail = nil; 

} 

@end 

답변

0

if (indexPath.row == 7) 당신은 일곱 행을 가지고있다 또한 선택 유형이 none.so 체크 할 수 있도록 가능한 한 8 행을 보여줍니다 일곱 번째 행을 표시하지 않습니다 그것 올바르게.

편집 :

당신이 일곱 번째 행은 다음 섹션 1에 액세스 할 수 있도록 6 행과 3 섹션을 만들고, 여기에 무슨 일이 일어나고 있는지 실제로

if (indexPath.section == 1 && indexPath.row==0) 

if(indexPath.row == 7) 라인을 변경해야 확인 행 0 similerly 13 행 2 섹션 및 행 0에 액세스해야합니다.

이제 나는 당신이 이해할 수 있다고 생각합니다.

+0

그래, 나도 알아, 0부터 셀 수 있습니다.하지만 그것을 클릭 할 수 없습니다, 나는 6 개의 행마다 그룹화 된 테이블을 가지고 있기 때문에. – WinterIsComing

+0

그래서 5 번보다 큰 indexPath.row를 삽입 할 때마다 ... 나는 그것을 클릭 할 수 없다 ... 왜 그런지 모르겠다. 단지 첫 번째 그룹화 된 셀이 작동하는 것 같다 .... 도움이된다 plz – WinterIsComing

+0

나는 생각한다. 델리게이트 및 데이터 소스 메서드에 대한 코드를 제공해야합니다. – Ishu

0

첫 번째 그룹을 클릭 할 수있는 한, 나는 그것이 테이블 셀을 만든 방식 때문이라고 생각합니다. 대체하려고 :


cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero 
                reuseIdentifier:@"cellID"] 

로 :


cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
                reuseIdentifier:@"cellID"] 

둘째 : 나는 당신이 (7 행이) 행 6 탭을 탐지하려고하는 이유를 이해하지 않습니다 당신이 정의 된 6 개 행이있을 때 각 tempArray. 클릭이 감지되지 않으므로 "자세히"보기 컨트롤러가 생성되지 않습니다.

관련 문제