UITableView madness

Posted by kesrut on Stack Overflow See other posts from Stack Overflow or by kesrut
Published on 2010-03-16T17:27:35Z Indexed on 2010/03/16 17:31 UTC
Read the original article Hit count: 349

Filed under:
|
|
|
|

Hello,

I'm new to iPhone application development. I'm trying to understand how to use UITableView.

I'm wrote simple code:

- (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 shows content, but if i'm drag table contents my application terminates. You can see video: http://www.youtube.com/watch?v=TucTVJVhSD0

I tried to everything with array:

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

Content is shown and if I'm selecting item i'm getting: [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

I'm total new to iPhone programming. And as i see everything i do - i'm just getting application terminated ..

© Stack Overflow or respective owner

Related posts about iphone

Related posts about cocoa