HI guy, I have another time a big problem that I don't understand.
I'm working with tableView's and I'm trying to create a simple example.
My problem is that when I acces at dictionary(is the array containing my cars) the program crash. I can't understand why I can acces from everywhere in my program but when I try to acces from "(UITableViewCell *) tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath" it doesn't work.
I think it can be a storage problem, hte visibilitie of that function isn't the same as the one from my class. I'm destroing my brain on my desk on those day.
pleaseee helppp meeee :-DDD
rgds
I'm working with tableView's and I'm trying to create a simple example.
Code:
//
// EBDisplayList.m
// TableView
//
// Created by Beit on 11.08.08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
#import "EBDisplayList.h"
@implementation EBDisplayList
@synthesize dictionary;
static EBDisplayList *sharedEBDisplayListInstance = nil;
+(EBDisplayList*) sharedEBDisplayList {
@synchronized(self) {
if (sharedEBDisplayListInstance == nil) {
[[self alloc] init];
}
}
return sharedEBDisplayListInstance;
}
-(id) init {
if (self = [super init]) {
}
TestaRossa = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"Ferrari",@"TestaRossa",nil] forKeys:[NSArray arrayWithObjects:@"Marca",@"Modello",nil]];
F430 = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"Ferrari",@"F430",nil] forKeys:[NSArray arrayWithObjects:@"Marca",@"Modello",nil]];
Maranello = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"Ferrari",@"Maranello",nil] forKeys:[NSArray arrayWithObjects:@"Marca",@"Modello",nil]];
TT = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"Audi",@"TT",nil] forKeys:[NSArray arrayWithObjects:@"Marca",@"Modello",nil]];
S3 = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"Audi",@"S3",nil] forKeys:[NSArray arrayWithObjects:@"Marca",@"Modello",nil]];
Ferrari = [NSArray arrayWithObjects:TestaRossa, F430, Maranello,nil];
Audi = [NSArray arrayWithObjects:TT, S3,nil];
dictionary = [NSArray arrayWithObjects:Ferrari,Audi,nil];
return self;
}
-(NSDictionary *) dictionaryValueForIndexPath:(NSIndexPath *)indexPath {
return ((NSDictionary *)[[dictionary objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]);
}
-(NSDictionary *) dictionaryValueForSection:(NSInteger)section andRow:(NSInteger)row {
return ((NSDictionary *)[[dictionary objectAtIndex:section] objectAtIndex:row]);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *) tableView {
//Number of sections is the number of model dictionaries
return [dictionary count];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
//Number of rows is the number of names in the model dictionary fot the specified section
return [[dictionary objectAtIndex:section] count];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Ide"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0.0, 0.0, 0, 0) reuseIdentifier:@"Ide"] autorelease];
}
// I TRIED THOSE TWO SOLUTION BUT DOESN'T WORK
cell.text = [[[[EBDisplayList sharedEBDisplayList] dictionaryValueForIndexPath:indexPath] objectForKey:@"Modello"] description];
cell.text = [[self dictionaryValueForIndexPath:indexPath] objectForKey:@"Modello"] description];
return cell;
}
-(void) dealloc {
[dictionary release];
//[keys release];
//[objects release];
[super dealloc];
}
@end
My problem is that when I acces at dictionary(is the array containing my cars) the program crash. I can't understand why I can acces from everywhere in my program but when I try to acces from "(UITableViewCell *) tableViewUITableView *)tableView cellForRowAtIndexPathNSIndexPath *)indexPath" it doesn't work.
I think it can be a storage problem, hte visibilitie of that function isn't the same as the one from my class. I'm destroing my brain on my desk on those day.
pleaseee helppp meeee :-DDD
rgds