In table view there are so many rows, when I click on any table view row it will expand like above example.
So, in this way I want to show some other data, I don’t want to navigate to next view.
Here another point is, after clicking on particular row when it expand then here I want to show web view. In my project, some data are messages some lines of text or may be a webpage. So, it has to show web view also and it has to adjust the tableview cell dynamically according to the data or web content.
Like that, if click any cell it has to be expand and show web view. Even sometime it does not contain any web data may be contain some msg then it has to be display web view.
Here is my current project sample. I am displaying the data/information following way. Here is my table view (see image 1) and after clicking on row it show a popup like this (see image 2)- It contain some message so showing like this, and image 3 - it contains web data/ webview.
If anybody knows the solution, then please post the solution. Thank you..!
Here is my didSelectRowAtIndexPath method,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSDictionary *finaldic=[mutableArray objectAtIndex:indexPath.row];
[self showWebview:@"" body:[finaldic objectForKey:@"body"] popupStyle:CNPPopupStyleActionSheet];
}
and WebView method,
-(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{
}
check my following code, it will help you..! I created according to your code.
Here is your didSelectRowAtIndexPath method,
- (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 ];
}
Write this method,
-(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;
}
}
and in cellForRowAtIndexPath method, add this 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];
I hope, this will work for you..!