Je suis nouveau dans le développement d'applications iPhone. J'essaie de comprendre comment utiliser UITableView.iPhone: UITableView, Glisser le contenu de la table provoque un crash
Je suis écrit le code simple:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1 ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
cell.textLabel.text = @"Hello";
return cell;
}
uitable affiche le contenu, mais si je suis le contenu de la table de glisser mon application se termine. Vous pouvez voir la vidéo: http://www.youtube.com/watch?v=TucTVJVhSD0
J'ai essayé de tout avec tableau:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1 ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [hello count] ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
cell.textLabel.text = [hello objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
NSLog(@"Selected") ;
}
- (void) awakeFromNib
{
hello = [[NSArray alloc] initWithObjects:@"hello", @"world", @"end", nil];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
Le contenu est affiché et si je l'article sélection J'obtiens:
[Session started at 2010-03-16 19:21:48 +0200.]
2010-03-16 19:21:52.295 ViewTest[1775:207] *** -[ViewTestViewController respondsToSelector:]: message sent to deallocated instance 0x3911ec0
Je suis totale nouveau à la programmation iPhone. Et comme je vois tout ce que je fais - je viens de terminer l'application.
Non, je n'implémente aucun protocole. Je viens de définir dataSource à mon ViewTestViewController dans IB. #import @interface ViewTestViewController: UIViewController { \t NSArray * bonjour; } @fin –
kesrut