TableView problem... duplication of some array items.

Discussion in 'iOS Programming' started by moomy, Sep 13, 2010.

  1. moomy macrumors newbie

    Joined:
    Apr 28, 2010
    #1
    Hi there,

    I have this problem, my programme works a treat but when I scroll down the table view it is fine, but then, after it gets to the last cell from the array, if I continue to scroll down it duplicates some of the items which have already been displayed and puts them into cells again.

    The array is read from plist files.

    here is the method.

    Code:
    
    
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;
    }
    
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return myList.count;
    }
    
    
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        
        static NSString *CellIdentifier = @"Cell";
        
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
    	
    	// Configure the cell.
    	cell.textLabel.text = [myList objectAtIndex:indexPath.row];
    	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        return cell;
    }
    

    not sure if the problem is here?

    quite new to this and a bit confused. If anyone has any ideas that would be great.
    thanks
    moomy:)
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    So, you're saying that your tableView is showing more rows than there are elements in your myList array? For example, your array contains 10 items but if you scroll down, the table displays 12 rows?
     
  3. Sykte macrumors regular

    Joined:
    Aug 26, 2010
    #3
    What does your plist look like. Also post the code you use to fill your array.
     
  4. moomy thread starter macrumors newbie

    Joined:
    Apr 28, 2010
    #4
    Thanks for replying. I have now figured it out. The scrolling enabled box in interface builder was checked by default. Once unchecked it seems to be working ok. :)
     

Share This Page