Je charge des données dans un UITableView
, à partir d'un UITableViewCell
personnalisé (propre classe et plume). Cela fonctionne très bien, jusqu'à ce que j'essaie d'accéder au objectAtIndex:indexPath.row
pour certaines baies.cellForRowAtIndexPath: se bloque lors de la tentative d'accès à des tableaux objectAtIndex: indexPath.row
Je posterai d'abord mon code, il vous sera probablement plus facile de comprendre ce que je veux dire.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"CustomCell";
CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[CustomCell class]]){
cell = (CustomCell *) currentObject;
break;
}
}
}
// Configure the cell...
NSUInteger row = indexPath.row;
cell.titleLabel.text = [postsArrayTitle objectAtIndex:indexPath.row];
cell.dateLabel.text = [postsArrayDate objectAtIndex:indexPath.row];
cell.cellImage.image = [UIImage imageWithContentsOfFile:[postsArrayImgSrc objectAtIndex:indexPath.row]];
return cell;
}
La chose étrange est, il ne fonctionne pas quand il charge dans les trois premières cellules (elles sont 130px de haut), mais se bloque lorsque je tente de faire défiler vers le bas. (AKA, le journal affiche trois numéros avant qu'il ne tombe en panne, 0, 1, 2
)
Alors, comme un résumé, les objectAtIndex:indexPath.row
pistes 3 * 3 fois avec succès, mais lorsque je tente de faire défiler vers le bas dans l'application, le chargement dans les cellules nouvelles, les application se bloque avec l'erreur suivante:
2010-05-30 14:00:43.122 app[2582:207] -[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x5a44bf0
2010-05-30 14:00:43.124 app[2582:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x5a44bf0'
// Stack
0 CoreFoundation 0x02398c99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x024e65de objc_exception_throw + 47
2 CoreFoundation 0x0239a7ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x0230a496 ___forwarding___ + 966
4 CoreFoundation 0x0230a052 _CF_forwarding_prep_0 + 50
5 myappname 0x00002ab1 -[HomeTableViewController tableView:cellForRowAtIndexPath:] + 605
informations complémentaires sur les tableaux:
les tableaux sont créés dans le fichier .h
:
NSArray *postsArrayDate;
NSArray *postsArrayTitle;
NSArray *postsArrayComments;
NSArray *postsArrayImgSrc;
Et rempli dans le viewDidLoad:
:
NSURL *urlPosts = [NSURL URLWithString:@"http://mysite/myphpfile.php?posts=2"]; //returns data in this format: DATA1#Data1.1#data1.2~DATA2#data2.1#~ and so on.
NSError *lookupError = nil;
NSString *data = [[NSString alloc] initWithContentsOfURL:urlPosts encoding:NSUTF8StringEncoding error:&lookupError];
postsData = [data componentsSeparatedByString:@"~"];
[data release], data = nil;
urlPosts = nil;
postsArrayDate = [[postsData objectAtIndex:2] componentsSeparatedByString:@"#"];
postsArrayTitle = [[postsData objectAtIndex:3] componentsSeparatedByString:@"#"];
postsArrayComments = [[postsData objectAtIndex:4] componentsSeparatedByString:@"#"];
postsArrayImgSrc = [[postsData objectAtIndex:5] componentsSeparatedByString:@"#"];
Comment puis-je corriger cet accident?
Si quelqu'un veut m'expliquer pourquoi utiliser self.array dans viewDidLoad lors du remplissage des tableaux, je vais accepter cette réponse. Je vous remercie. – Emil
Et ce que le soi. la partie fait dans d'autres comparaisons. – Emil
Je suis désolé, mais je n'ai pas la moindre idée de la raison pour laquelle ajouter 'self.' à' postsArrayDate', etc résolu ... –