2017-10-10 3 views
0

テーブルビューには非常に多くの行があります。テーブルビュー行をクリックすると、上記の例のように展開されます。 Example特定のUITableView行をクリックした後にWebViewデータを表示する方法は?

このように、他のデータを表示したいので、次のビューに移動したくありません。

ここで別のポイントは、展開するときに特定の行をクリックした後、ここで私はWebビューを表示したいと思います。私のプロジェクトでは、一部のデータはメッセージの一部のテキスト行であるか、ウェブページである可能性があります。 したがって、Webビューも表示する必要があり、データまたはWebコンテンツに従って動的にtableviewセルを調整する必要があります。

このように、任意のセルをクリックすると展開してウェブビューを表示する必要があります。いつかは、ウェブデータが含まれていない場合でも、いくつかのメッセージが含まれている可能性があります。

ここに私の現在のプロジェクトサンプルがあります。私は次のようにデータ/情報を表示しています。 これは私のテーブルビューです(画像1を参照)。これをクリックすると、このようなポップアップが表示されます(画像2を参照) - このようなメッセージが表示され、画像3 - Webデータ/ webviewが含まれます。

誰かが解決策を知っている場合は、解決策を投稿してください。ありがとうございました..!ここで enter image description here

ちょうど2つの異なるテーブルビューセルをデザインシンプルで私のdidSelectRowAtIndexPath方法、

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

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

と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

あなたは客観的なcまたはswiftを使用していますか? –

+1

試したコードを追加してください。 –

+0

@ R.Mohanこれは目的コードです。 –

答えて

1

私の次のコードをチェックすると、あなたを助けるでしょう..!私はあなたのコードに従って作成しました。ここで

は、あなたの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 ]; 

} 

書き込みは、この方法、

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

とcellForRowAtIndexPathメソッドでは、私は願ってい

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]; 

このコードを追加し、これがために動作しますです君は..!

+0

ありがとう...!これは私の仕事です...! –

0

です。 1つはシンプルで、もう1つは拡張セルです。単純なセルをクリックすると、特定のセルを展開してセルを変更します。

関連する問題