2011-08-24 15 views
8

पर सबव्यूव्यू जोड़ें जब मैं UITableViewCell में सबव्यूव्यू जोड़ता हूं तो मुझे परेशानी होती है। यह काम कर रहा है जब तालिका का आकार आईफोन आकार से नीचे है।UITableViewCell

लेकिन जब आकार बड़ा है, तो वह ऐसा कुछ भयानक प्रभाव जब मैं स्क्रॉल कर रहा हूँ बनाता है:

enter image description here

यह इस तरह होना चाहिए था:

enter image description here तो मैं यह लगता है सेल पुन: उपयोग से आता है। यहाँ मेरी कोड का एक नमूना है:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *kCellIdentifier = @"UITableViewCellStyleSubtitle"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier]; 
    if (cell == nil) { 
     //construct the cell 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle 
             reuseIdentifier:kCellIdentifier] autorelease]; 


     //clear the previuous content 
     NSLog(@"Il y a %d subviews", [[[cell contentView] subviews] count]); 
     //[[[cell contentView] subviews] makeObjectsPerformSelector: @selector(removeFromSuperview)]; 
     NSLog(@"Il y a %d subviews", [[[cell contentView] subviews] count]); 
     [[cell textLabel] setBackgroundColor:[UIColor clearColor]]; 
     [cell setSelectionStyle:UITableViewCellEditingStyleNone]; 
    }  

    switch (indexPath.row) { 
     case 0: 
      [cell addSubview:titleEvent]; 
      break; 
     case 1: 
      //load the owner logo 
      [cell addSubview:logoAsso]; 
      break; 
     case 2: 
      //StartDate 
      [cell addSubview:clockImage]; 
      break; 
     case 3: 
      //EndDate 
      [cell addSubview:clockEndImage]; 
      break; 
     case 4: 
      //Address 
      [cell addSubview:adress]; 
      break; 
     case 5: 
      //map 
      [cell addSubview:map]; 
      break; 
     case 6: 
      //header 
      [Graphism configureSeparationCell:cell]; 
      break; 
     case 7: 
      //descritpion 
      [cell addSubview:descriptionEvent]; 
      break; 
     default: 
      break; 
    } 
    return cell; 
} 

subviews वर्ग के attributs, और विधि viewDidLoad में विन्यस्त कर रहे हैं। यदि आप मुझे बता सकते हैं कि मैं क्या गलत कर रहा हूं, तो यह इतनी राहत होगी।

उत्तर

4
switch (indexPath.row) { 
    case 0: 


     if (![cell.contentView viewWithTag:11]) { 

      titleEvent.tag = 11; 

      [cell.contentView addSubview:titleEvent]; 
     } 


     break; 
    case 1: 
     if (![cell.contentView viewWithTag:11]) { 

      logoAsso.tag = 11; 

      [cell.contentView addSubview:logoAsso]; 
     } 

इस तरह सभी स्विच मामलों के लिए कर

-3

[cell.contentView addSubview: clockImage];

5

इस कोड

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellIdentifier"]; 

    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellIdentifier"] autorelease]; 

    } else { 
     UIView *subView = (UIView *)[cell.contentView viewWithTag:1]; 
     if ([subView superview]) { 
      [subView removeFromSuperview]; 
     } 
    } 

    UIView *subView = [[UIView alloc] init]; 
    subView.tag = 1; 
    [cell.contentView addSubview:subView]; 
    [subView release]; 

    return cell; 
} 
प्रयास करें