【发布时间】:2018-03-21 15:52:09
【问题描述】:
在表格视图中有很多行,当我单击任何表格视图行时,它会像上面的示例一样展开。
所以,通过这种方式我想显示一些其他数据,我不想导航到下一个视图。
这里还有一点是,当它展开时单击特定行后,我想在这里显示网络视图。在我的项目中,一些数据是一些文本行的消息,或者可能是一个网页。 因此,它还必须显示 web 视图,并且必须根据数据或 web 内容动态调整 tableview 单元格。
像这样,如果单击任何单元格,它必须展开并显示 web 视图。即使有时它不包含任何网络数据,也可能包含一些味精,那么它必须是显示网络视图。
这是我当前的项目示例。我正在按照以下方式显示数据/信息。 这是我的表格视图(参见图 1),单击行后会显示这样的弹出窗口(参见图 2)- 它包含一些消息,因此显示如下,图 3 - 它包含网络数据/网络视图。
这是我的 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{
}
【问题讨论】:
-
你使用的是objective c还是swift?
-
添加您尝试过的代码。
-
@R.Mohan 这是 Objective c 代码。
-
之前你没有添加任何代码,这就是我问它的原因,现在添加了标签objective-c。
标签: ios objective-c iphone uitableview uiwebview