开发者

Problem with Xcode, iphone, while programming a table

i have a grouped table, and if i write:

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

It doesn't click on the 7th row...

I have this kind of UITableView (grouped):

- (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];
}

Do i need something different than ==7?

Thank you in advance

Whole code:

#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 penn开发者_运维知识库elli",@"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


if (indexPath.row == 7) does not show seventh row it shows 8th row so possible you are having only seven row and also selection type may be none.so check it correctly.

Edit:

ok you need to change if(indexPath.row == 7) line to

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

actually what is going on here,you are making 3 section with 6 rows so for seventh row you can access section 1 then row 0 similerly for accesing 13th row you need to access 2nd section and row 0.

Now i think you can understand.


As far as the 1st group can be clicked only, I believe it is due to the way you created the table cells. Try to replace:


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

with:


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

Second: I don't understand why you are trying to detect tap on row 6 (which is 7th row) when you have 6 rows defined on each tempArray. For sure that click will never been detect and so "detail" view controller will never be created.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜