2017-10-10 20 views
0

Dans la vue de table il y a tellement de rangées, quand je clique sur n'importe quelle rangée de vue de table elle développera comme l'exemple ci-dessus. Comment afficher les données WebView après avoir cliqué sur une ligne UITableView particulière?

Donc, de cette façon, je veux montrer d'autres données, je ne veux pas passer à la vue suivante.

Voici un autre point, après avoir cliqué sur une ligne particulière quand elle se développe alors ici je veux montrer la vue web. Dans mon projet, certaines données sont des messages certaines lignes de texte ou peuvent être une page Web. Ainsi, il doit également afficher la vue Web et ajuster dynamiquement la cellule tableview en fonction des données ou du contenu Web. Ainsi, si vous cliquez sur une cellule, elle doit être agrandie et afficher la vue Web. Même parfois, il ne contient pas de données Web peuvent contenir des msg alors il doit être l'affichage web.

Voici mon exemple de projet actuel. J'affiche les données/informations de la manière suivante. Voici ma vue de la table (voir image 1) et après avoir cliqué sur la ligne, elle affiche une fenêtre comme celle-ci (voir image 2) - Elle contient un message comme celui-ci, et l'image 3 - contient données web/webview.

Si quelqu'un connaît la solution, veuillez poster la solution. Je vous remercie..! enter image description here

Voici ma méthode de didSelectRowAtIndexPath,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 

    NSDictionary *finaldic=[mutableArray objectAtIndex:indexPath.row]; 
    [self showWebview:@"" body:[finaldic objectForKey:@"body"] popupStyle:CNPPopupStyleActionSheet]; 
} 

et méthode WebView,

-(void)showWebview:(NSString*)tittle body:(NSString*)body popupStyle:(CNPPopupStyle)popupStyle{ 

    NSMutableParagraphStyle *paragraphStyle = NSMutableParagraphStyle.new; 
    paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping; 
    paragraphStyle.alignment = NSTextAlignmentCenter; 

    NSAttributedString *title = [[NSAttributedString alloc] initWithString:tittle attributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:14], NSParagraphStyleAttributeName : paragraphStyle}]; 

    UILabel *titleLabel = [[UILabel alloc] init]; 
    titleLabel.numberOfLines = 0; 
    titleLabel.attributedText = title; 

    // UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 40)]; 
    // customView.backgroundColor = [UIColor hx_colorWithHexString:@"#00aeef"]; 
    //  [customView addSubview:titleLabel]; 

    UIWebView *webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width,self.view.frame.size.height/2)]; 
    // webview.scalesPageToFit = YES; 
    webview.autoresizesSubviews = YES; 
    //webview.delegate=self; 
webview.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth); 

    NSRange range = [body rangeOfString:@"<body"]; 

    if(range.location != NSNotFound) { 
     // Adjust style for mobile 
     float inset = 40; 
     NSString *style = [NSString stringWithFormat:@"<style>div {max-width: %fpx;}</style>", self.view.bounds.size.width - inset]; 
     body = [NSString stringWithFormat:@"%@%@%@", [body substringToIndex:range.location], style, [body substringFromIndex:range.location]]; 
    } 
    [webview loadHTMLString:body baseURL:nil]; 


    self.popupController = [[CNPPopupController alloc] initWithContents:@[titleLabel,webview]]; 
    self.popupController.theme = [CNPPopupTheme defaultTheme]; 
    self.popupController.theme.popupStyle = popupStyle; 
    self.popupController.delegate = self; 
    [self.popupController presentPopupControllerAnimated:YES]; 
} 

- (void)webViewDidFinishLoad:(UIWebView *)webView { 

} 
-(void)webViewDidStartLoad:(UIWebView *)webView{ 

} 
+0

vous utilisez l'objectif c ou rapide? –

+1

Ajoutez votre code essayé. –

+0

@ R.Mohan Ceci est le code Objective c. –

Répondre

1

vérifier mon code suivant, il vous aidera ..! J'ai créé selon votre code.

Voici votre méthode didSelectRowAtIndexPath,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 



    //user taps expnmade view 

    if(selectedIndex == indexPath.row) 
    { 

     selectedIndex =-1; 
     [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade ]; 
     return; 
    } 

    //user taps diff row 
    if(selectedIndex != -1) 
    { 

     NSIndexPath *prevPath= [NSIndexPath indexPathForRow:selectedIndex inSection:0]; 
     selectedIndex=(int)indexPath.row; 

     [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:prevPath, nil] withRowAnimation:UITableViewRowAnimationFade ]; 
    } 


    //user taps new row with none expanded 
    selectedIndex =(int)indexPath.row; 
    [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationFade ]; 

} 

écrire cette méthode,

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    if(selectedIndex == indexPath.row) 
    { 
     // return 200; 

     UITableViewCell *cell = [self tableView: tableView cellForRowAtIndexPath: indexPath]; 
     return cell.bounds.size.height; 
    } 
    else 
    { 
     return 90; 
    } 
} 

et méthode cellForRowAtIndexPath, ajoutez ce code

NSDictionary *finaldic=[mutableArray objectAtIndex:indexPath.row]; 



    NSString *body= [finaldic objectForKey:@"body"]; 
    NSRange range = [body rangeOfString:@"<body"]; 

    if(range.location != NSNotFound) { 
     // Adjust style for mobile 
     float inset = 40; 
     NSString *style = [NSString stringWithFormat:@"<style>div {max-width: %fpx;}</style>", self.view.bounds.size.width - inset]; 
     body = [NSString stringWithFormat:@"%@%@%@", [body substringToIndex:range.location], style, [body substringFromIndex:range.location]]; 
    } 
    [cell.webView loadHTMLString:body baseURL:nil]; 

je l'espère, cela fonctionnera pour toi..!

+0

merci ...! C'est un travail pour moi ...! –

0

Il est simple simplement concevoir deux cellules de vue de table différents. L'un est simple et l'autre étend la cellule. Lorsque vous cliquez sur Cellule simple, changez la cellule spécifique pour développer la cellule.