2012-03-26 2 views
0

Как говорит название: Мои данные пользовательские ячейки исчезает, если выбрать его и прокручивать его из экранаМои данные пользовательские ячейки исчезает, если выбрать его и прокручивать его из экрана

Мой список заполняется, но после didSelectRowAtIndexPath и прокрутки экрана больше не отображаются данные.

Пила разные посты в интернете, но никто не приблизился к моей ситуации, поэтому я надеюсь, что кто-то найдет ответ.

Ниже приведен код для cellForRowAtIndexPath и didSelectRowAtIndexPath.

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

/* 
    UITableViewCell: USE THE SAME IDENTIFIER FOR EVERY CELL IF YOU ARE NOT USING ICONS 
    Like This... 
    static NSString *CellIdentifier = @"Cell"; 
*/ 
NSString *CellIdentifier = [NSString stringWithFormat:@"cell_%i", indexPath.row]; 

BT_cell_menuList *cell = (BT_cell_menuList *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 

    //init our custom cell 
    cell = [[[BT_cell_menuList alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

} 

//this menu item 
BT_item *thisMenuItemData = [self.menuItems objectAtIndex:indexPath.row]; 
[cell setTheMenuItemData:thisMenuItemData]; 
[cell setTheParentMenuScreenData:[self screenData]]; 
[cell configureCell]; 

//custom background view. Must be done here so we can retain the "round" corners if this is a round table 
//this method refers to this screen's "listRowBackgroundColor" and it's position in the tap. Top and 
//bottom rows may need to be rounded if this is screen uses "listStyle":"round" 
[cell setBackgroundView:[BT_viewUtilities getCellBackgroundForListRow:[self screenData]:indexPath:[self.menuItems count]]]; 

//return  
return cell;  


} 


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
[BT_debugger showIt:self:@"didSelectRowAtIndexPath"]; 

//get the rss 
BT_rssItem *theRssItem = [self.rssItems objectAtIndex:indexPath.row]; 

//pass this menu item to the tapForMenuItem method 
BT_item *thisMenuItem = [self.menuItems objectAtIndex:indexPath.row]; 

//build a BT_screen_webView to load. Give it an itemId that matches the menuItems 
//loadScreenWithItemId value so we BT_viewControllManager can find it. 
NSString *theDynamicScreenItemId = [thisMenuItem itemId]; 

BT_item *theDynamicScreenObjectToLoad = [[BT_item alloc] init]; 
[theDynamicScreenObjectToLoad setItemId:theDynamicScreenItemId]; 
[theDynamicScreenObjectToLoad setItemType:@"BT_screen_webView"]; 

//dictionary for menu row tapped 
NSDictionary *menuDict = [NSDictionary dictionaryWithObjectsAndKeys: 
theDynamicScreenItemId, @"itemId", 
@"BT_menuItem", @"itemType", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemRowTapTransitionType":@""], @"transitionType", nil]; 
[thisMenuItem setJsonVars:menuDict]; 

//create a dictionary for the dynamic screen. 
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys: 
theDynamicScreenItemId, @"itemId", 
@"BT_screen_webView", @"itemType", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"navBarTitleText":@""], @"navBarTitleText", 
theRssItem.linkURL, @"dataURL", 

//these are the optional properties the BT_screen_webView will look for 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemNavBarBackgroundColor":@""], @"navBarBackgroundColor", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemNavBarStyle":@""], @"navBarStyle", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemToolBarStyle":@""], @"toolBarStyle", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemBackButtonText":@""], @"navBarBackButtonText", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemBackgroundColor":@""], @"backgroundColor", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemShowBrowserBarBack":@"0"], @"showBrowserBarBack", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemShowBrowserRefresh":@"0"], @"showBrowserBarRefresh", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemShowBrowserBarLaunchInNativeApp":@"0"], @"showBrowserBarLaunchInNativeApp", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemNavBarRightButtonType":@""], @"navBarRightButtonType", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemNavBarRightButtonTapLoadScreenItemId":@""], @"navBarRightButtonTapLoadScreenItemId", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemRightButtonTapTransitionType":@""], @"navBarRightButtonTapTransitionType", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemHideBottomTabBarWhenScreenLoads":@""], @"hideBottomTabBarWhenScreenLoads", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemAudioFileName":@""], @"audioFileName", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemAudioFileURL":@""], @"audioFileURL", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemAudioStopsOnScreenExit":@"0"], @"audioStopsOnScreenExit", 
[BT_strings getJsonPropertyValue:self.screenData.jsonVars:@"rssItemAudioNumberOfLoops":@"0"], @"audioNumberOfLoops", 
nil]; 

//set the dictionary for the dynamic screen 
[theDynamicScreenObjectToLoad setJsonVars:dict]; 

//BT_viewControllerManager will launch the next screen 
[BT_viewControllerManager handleTapToLoadScreen:[self screenData]:thisMenuItem:theDynamicScreenObjectToLoad]; 

//clean up 
[theDynamicScreenObjectToLoad release]; 
theDynamicScreenObjectToLoad = nil; 

} 

Если требуется больше кода, я с удовольствием сообщаю.

Спасибо заранее, D

Дополнительная информация OKI'll показать метод configurecell здесь. Может быть, кто-то видит, что я пропускаю

-(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

Можете ли вы подтвердить, имеет ли значение выбор. Если вы просто прокручиваете без выбора, это сработает? – danh

+0

Обычный виновник в этом случае является условным где-то в конфиге ячейки. Если (x) {добавить что-то в ячейку}, но пропустить else {вычесть что-то, если не x}. Это может быть в вашем configCell: method. – danh

+0

Привет, дан, спасибо, что вернулись ко мне. Прокрутка без выбора работает без особых проблем. Просто выберите строку, и все закончится .... – Danny

ответ

-1

Удалить условие: - если (ячейка == ноль) {

от метода cellForRowAtIndexPath.

А также поставил условие в том же методе cellForRowAtIndexPath

, что ([кол self.menuItems] indexpath.row <) если {

// помещаем все случаи здесь

}

+0

Привет, Вики, я удалил: if (cell == nil) {и заменил его на: f (indexpath.row <[self.menuItems count]) {но это не сработало. Такое же поведение происходит. любые идеи были бы замечательными – Danny

+0

не заменяли его if (indexpath.row <[self.menuItems count]) просто поместите это условие перед вашей логической частью в ячейку для строки по методу указателя пути. – Wish