UITableView Crash when scrolling

Discussion in 'iOS Programming' started by PizzaTray, Dec 15, 2009.

  1. PizzaTray macrumors newbie

    Joined:
    Oct 31, 2009
    #1
    When i scroll my table its crash.
    Code:
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return [self.list count];
    }
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        
        static NSString *CellIdentifier = @"Cell";
        
        CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[CustomCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
        }
    	switch (indexPath.row) {
    		case 0:
    			cell.Label.text = [[self.list objectAtIndex:indexPath.row]retain];
    			cell.imageView.image = [self.picArr objectAtIndex:0];
    			break;
    		case 1:
    			cell.Label.text = [[self.list objectAtIndex:indexPath.row]retain];
    			cell.imageView.image = [self.picArr objectAtIndex:0];
    			break;
    		case 2:
    			cell.Label.text = [[self.list objectAtIndex:indexPath.row]retain];
    			cell.imageView.image = [self.picArr objectAtIndex:0];
    			break;
    .
    .
    .
    		default:
    			break;
    	}
    	cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        return cell;
    
    help someone?:confused:
     
  2. Troglodyte macrumors member

    Joined:
    Jul 2, 2009
    #2
    It's probably not causing your crashes but you don't need to retain the values you're assigning to the label.

    I'm pretty certain the property is not called 'Label' either. If you're on 3.x it's called 'textLabel'.
     
  3. johnnyjibbs macrumors 68030

    johnnyjibbs

    Joined:
    Sep 18, 2003
    Location:
    London, UK
    #3
    What do the crash logs say? Have you got an index out of bounds error? A memory error (e.g. overreleased object, etc)?

    It looks as if there is not enough information visible to be able to concretely determine the cause of the crash. It could be all manner of things. Check that your label is a UILabel, your imageView is a UIImageView, your pictures array contains UIImage objects, your list data array contains NSStrings. If any of these don't you could get a crash.

    I noticed you are accessing a property of your custom table view cell called Label - did you mean to have capitals? Remember that objective-C is case-sensitive. The default label property since 3.0 is textLabel.

    Why do you need the switch statement? Looks like you do the same thing regardless of row? The text is stored in your list data array so you don't need it.

    I would get rid of the retains as well for the text - you are causing memory leaks here...
     

Share This Page