2012-03-26 2 views
0

Wie der Titel schon sagt: Meine benutzerdefinierten Zellendaten verschwinden, wenn ich es wählen und blättern Sie es auf dem Bildschirm ausMeine benutzerdefinierten Zellendaten verschwinden, wenn ich es wählen und blättern Sie es aus dem Bildschirm

Meine Liste gut bestückt ist aber Nach dem didSelectRowAtIndexPath und Scrollen aus dem Bildschirm werden keine Daten mehr angezeigt.

Sah verschiedene Beiträge im Internet, aber keine kamen zu meiner Situation, so hoffe ich, jemand kann eine Antwort finden.

Unten ist der Code für den cellForRowAtIndexPath und didSelectRowAtIndexPath.

Wenn mehr Code benötigt wird, bin ich glücklich zu teilen.

Vielen Dank im Voraus, D

Zusatzinfo OKI'll hier die configurecell Methode zeigen. Vielleicht sieht jemand, was ich

-(void)configureCell{ 

//appDelegate 
ironmaiden_appDelegate *appDelegate = (ironmaiden_appDelegate *)[[UIApplication sharedApplication] delegate]; 

/* 
    cell design comes from rootApp.rootTheme OR from parentScreen's JSON data if over-ridden 
    Scenarios: 
     a) Title NO Description. 
      In this case, the row-height is used for the label the text is centered. 
     b) Title + Description. 
      In this case, the "listTitleHeight" is used and the the difference between this and 
      the row-height becomes the height of the description label 

    IMPORTANT: The image with be center in the image box. This means if the image is larger than 
    the row height it will not look right. Scaling images in lists is memory intensive so we do 
    not do it. This means you should only use icons/images that are "smaller than the row height"   


*/ 

//default values 
int rowHeight = 50; 
int titleHeight = 50; 
int descriptionHeight = 0; 
int iconSize = 50; 
int iconLeft = 0; 
int iconPadding = 0; 
int iconRadius = 0; 
int titleFontSize = 20; 
int descriptionFontSize = 20; 
UIColor *titleFontColor = [UIColor blackColor]; 
UIColor *descriptionFontColor = [UIColor blackColor]; 
NSString *iconName = @""; 
NSString *iconURL = @""; 
NSString *iconScale = @"center"; 
NSString *applyShinyEffect = @"0"; 
NSString *rowSelectionStyle = @"arrow"; 
NSString *useWhiteIcons = @"0"; 
NSString *rowAccessoryType = @""; 
NSString *titleText = @""; 
NSString *descriptionText = @""; 


//////////////////////////////////////////////////////////////////////// 
//properties not related to the device's size 

//listTitle/description 
titleText = [BT_strings getJsonPropertyValue:theMenuItemData.jsonVars:@"titleText":@""]; 
titleText = [BT_strings cleanUpCharacterData:titleText]; 
titleText = [BT_strings stripHTMLFromString:titleText]; 

descriptionText = [BT_strings getJsonPropertyValue:theMenuItemData.jsonVars:@"descriptionText":@""]; 
descriptionText = [BT_strings cleanUpCharacterData:descriptionText]; 
descriptionText = [BT_strings stripHTMLFromString:descriptionText]; 

titleFontColor = [BT_color getColorFromHexString:[BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listTitleFontColor":@"#000000"]]; 
descriptionFontColor = [BT_color getColorFromHexString:[BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listDescriptionFontColor":@"#000000"]]; 
rowSelectionStyle = [BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listRowSelectionStyle":@"blue"]; 
iconScale = [BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listIconScale":@"center"]; 
applyShinyEffect = [BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listIconApplyShinyEffect":@"0"]; 

//icon name, radius, use rounded corners? 
iconName = [BT_strings getJsonPropertyValue:theMenuItemData.jsonVars:@"iconName":@""]; 
iconURL = [BT_strings getJsonPropertyValue:theMenuItemData.jsonVars:@"iconURL":@""]; 
iconRadius = [[BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listIconCornerRadius":@"0"] intValue]; 
useWhiteIcons = [BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listUseWhiteIcons":@"0"]; 

//row accessory type 
rowAccessoryType = [BT_strings getJsonPropertyValue:theMenuItemData.jsonVars:@"rowAccessoryType":@"arrow"]; 

//if the global theme or the parent screen use a "round" list type, button left changes so it's not against the edge 
NSString *parentListStyle = [BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listStyle":@"plain"]; 
if([parentListStyle isEqualToString:@"round"]){ 
    iconLeft = -5; 
    iconPadding = 7; 
} 

//center image or scale image? When using icons that are smaller than the row height it's best to center 
//when using images (usually from a URL) that are larger than the row height, use scale 
if([iconScale isEqualToString:@"scale"]){ 
    cellImageView.contentMode = UIViewContentModeScaleAspectFill; 
} 

//if we have an iconURL, and no iconName, figure out a name to use... 
if(iconName.length < 3 && iconURL.length > 3){ 
    iconName = [BT_strings getFileNameFromURL:iconURL]; 
} 

//////////////////////////////////////////////////////////////////////// 
//properties related to the device's size 

//height and size depends on device type 
if([appDelegate.rootApp.rootDevice isIPad]){ 

    //user large device settings 
    rowHeight = [[BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listRowHeightLargeDevice":@"50"] intValue]; 
    titleHeight = [[BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listTitleHeightLargeDevice":@"30"] intValue]; 
    titleFontSize = [[BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listTitleFontSizeLargeDevice":@"20"] intValue]; 
    descriptionFontSize = [[BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listDescriptionFontSizeLargeDevice":@"15"] intValue]; 
    iconSize = [[BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listIconSizeLargeDevice":@"50"] intValue]; 

}else{ 

    //user small device settings 
    rowHeight = [[BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listRowHeightSmallDevice":@"50"] intValue]; 
    titleHeight = [[BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listTitleHeightSmallDevice":@"30"] intValue]; 
    titleFontSize = [[BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listTitleFontSizeSmallDevice":@"20"] intValue]; 
    descriptionFontSize = [[BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listDescriptionFontSizeSmallDevice":@"15"] intValue]; 
    iconSize = [[BT_strings getStyleValueForScreen:theParentMenuScreenData:@"listIconSizeSmallDevice":@"50"] intValue]; 

} 

//figure out heights 
if(titleHeight > rowHeight){ 
    titleHeight = rowHeight; 
} 
if([descriptionText length] > 0){ 
    descriptionHeight = (rowHeight - titleHeight); 
}else{ 
    titleHeight = rowHeight; 
} 

//this is bound to happen! Users will enter a rowHeight that is the same as the titleHeight and 
//provide a description. In this case, it won't work because the title will cover the description. 
//ignore their settings in the case so they can see what they did and force them to adjust. 
if(titleHeight == rowHeight && [descriptionText length] > 0){ 
    titleHeight = (rowHeight/2); 
    descriptionHeight = (rowHeight/2); 
} 


//label size/position depend on whether or not we have an icon. 
if([iconName length] > 1){ 

    //are we using the white versions of icons? 
    if([useWhiteIcons isEqualToString:@"1"]){ 
     iconName = [BT_imageTools getWhiteIconName:iconName]; 
    } 

    //set the imageName and imageURL in the BT_item so it can find the icon, image, whatever 
    [self.theMenuItemData setImageName:iconName]; 
    [self.theMenuItemData setImageURL:iconURL]; 

    //frame for image/shine, etc 
    CGRect boxFrame = CGRectMake((iconLeft + iconPadding), 0, rowHeight, rowHeight); 
    CGRect imageFrame = CGRectMake((iconLeft + iconPadding) + 3, rowHeight/2 - (iconSize/2), iconSize, iconSize); 

    //set image frames 
    [imageBox setFrame:boxFrame]; 
    [cellImageView setFrame:imageFrame]; 
    [glossyMaskView setFrame:imageFrame]; 
    [imageLoadingView setFrame:imageFrame]; 

    //remove glossy mask if we don't want it 
    if([applyShinyEffect isEqualToString:@"0"]){ 
     [glossyMaskView removeFromSuperview]; 
    } 

    //round corners? Apply shadow? 
    if(iconRadius > 0){ 
     cellImageView = [BT_viewUtilities applyRoundedCornersToImageView:cellImageView:iconRadius]; 
    } 

    //text 
    int labelLeft = (iconSize + iconPadding + 8); 
    int labelWidth = self.contentView.frame.size.width - iconSize - iconPadding; 

    [titleLabel setFrame:CGRectMake(labelLeft, 0, labelWidth, titleHeight)]; 
    [descriptionLabel setFrame:CGRectMake(labelLeft, titleHeight - 5, labelWidth, descriptionHeight)]; 

    //show the image 
    [self showImage]; 

}else{ 

    //remove image frames 
    [cellImageView removeFromSuperview]; 
    [glossyMaskView removeFromSuperview]; 
    [imageLoadingView removeFromSuperview]; 

    //text  
    int labelLeft = 10 + iconPadding; 
    int labelWidth = self.contentView.frame.size.width - 25; 

    [titleLabel setFrame:CGRectMake(labelLeft, 0, labelWidth, titleHeight)]; 
    [descriptionLabel setFrame:CGRectMake(labelLeft, titleHeight - 5, labelWidth, descriptionHeight)]; 

} 

//set title 
[titleLabel setTextColor:titleFontColor]; 
[titleLabel setFont:[UIFont boldSystemFontOfSize:titleFontSize]]; 
[titleLabel setText:titleText]; 
[titleLabel setOpaque:FALSE]; 

//set description 
[descriptionLabel setTextColor:descriptionFontColor]; 
[descriptionLabel setFont:[UIFont systemFontOfSize:descriptionFontSize]]; 
[descriptionLabel setText:descriptionText]; 
[descriptionLabel setOpaque:FALSE]; 

//cell selection style: Blue, Gray, None 
if([rowSelectionStyle rangeOfString:@"blue" options:NSCaseInsensitiveSearch].location != NSNotFound){ 
    [self setSelectionStyle:UITableViewCellSelectionStyleBlue]; 
} 
if([rowSelectionStyle rangeOfString:@"gray" options:NSCaseInsensitiveSearch].location != NSNotFound){ 
    [self setSelectionStyle:UITableViewCellSelectionStyleGray]; 
} 
if([rowSelectionStyle rangeOfString:@"none" options:NSCaseInsensitiveSearch].location != NSNotFound){ 
    [self setSelectionStyle:UITableViewCellSelectionStyleNone]; 
} 

//chevron indicator: DisclosureButton, DetailDisclosureButton, Checkmark, None 
if([rowAccessoryType rangeOfString:@"arrow" options:NSCaseInsensitiveSearch].location != NSNotFound){ 
    [self setAccessoryType: UITableViewCellAccessoryDisclosureIndicator]; 
} 
if([rowAccessoryType rangeOfString:@"details" options:NSCaseInsensitiveSearch].location != NSNotFound){ 
    [self setAccessoryType: UITableViewCellAccessoryDetailDisclosureButton]; 
} 
if([rowAccessoryType rangeOfString:@"checkmark" options:NSCaseInsensitiveSearch].location != NSNotFound){ 
    [self setAccessoryType: UITableViewCellAccessoryCheckmark]; 
}  
if([rowAccessoryType rangeOfString:@"none" options:NSCaseInsensitiveSearch].location != NSNotFound){ 
    [self setAccessoryType: UITableViewCellAccessoryNone]; 
} 

}

+0

Können Sie bestätigen, ob die Auswahl wichtig ist? Wenn Sie nur blättern, ohne zu wählen, funktioniert es? – danh

+0

Der übliche Schuldige an diesen ist eine bedingte irgendwo in der Config a-Zelle. If (x) {füge etwas zur Zelle hinzu, aber fehlt else {subtrahiere etwas, wenn nicht x}. Das könnte in Ihrer configCell: -Methode sein. – danh

+0

Hallo Danh, Danke, dass du mich zurückbekommen hast. Das Scrollen ohne Auswahl funktioniert ohne Probleme. Einfach eine Zeile auswählen und es ist vorbei .... – Danny

Antwort

-1

Entfernen Sie den Zustand bin fehlt: - if (Zelle == null) {

von cellForRowAtIndexPath Methode.

und legte auch eine Bedingung in derselben Methode cellForRowAtIndexPath

, dass, wenn (indexpath.row < [self.menuItems count]) {

// alle Fälle setzen hier

}

+0

Hallo Vicky, ich entfernte das: if (cell == nil) {und ersetzte es durch: f (indexpath.row <[self.menuItems count]) {aber das hat nicht funktioniert. Das gleiche Verhalten passiert. alle Ideen wären großartig – Danny

+0

nicht ersetzen Sie es mit if (indexpath.row <[self.menuItems count]) nur diese Bedingung vor Ihrem logischen Teil in Zelle für Zeile bei Index-Pfad-Methode. – Wish

Verwandte Themen