[英]ios:convert html string to nsstring and display in uitableview?
我正在使用情節提要板完成我的項目,在我的項目中,我將解析json數據並顯示在模擬器中。 這是我的json
activityList = (
{
activityTitle = test;
activityType = Chat;
apiKey = null;
desc = "<p>asasasa</p>";
id = 361;
issueTitle = "Issue Created By m43 (194)";
sessionId = null;
status = true;
token = null;
when = "Sat, 30 Nov 2013 04:30 AM CET";
},
{
activityTitle = "test match private";
activityType = "One Way Video Streaming";
apiKey = null;
desc = "<p>test match private</p>";
id = 335;
issueTitle = "test match (190)";
sessionId = null;
status = true;
token = null;
when = "Fri, 29 Nov 2013 10:30 AM GMT";
},
我解析了json並在tableview中顯示了所有數據,除了此desc = "<p>test match private</p>";
a,在將該html字符串轉換為nsstring時遇到問題。 我如何嘗試並使用此轉換
desc1 = [[items valueForKey:@"desc"] componentsJoinedByString:@","];
NSLog(@"%@",desc1);
NSString *itemTitle = [desc1 stringByConvertingHTMLToPlainText];
NSLog(@"%@",itemTitle);
它印了我這個
<p>asasasa</p>,<p>test match private</p>,<p>test activity by m43</p>,<p>Test for chat activities</p>,<p>test 5 for admin</p>,<p>test ca activity title</p>,<p>test for video issue</p>,<p>activity for m43 by c31</p>,<p>test activity title community activism By u1</p>,<p>test 7</p>,<p>test</p>,<p>chat</p>,<p>rahul jaykar</p>,<p>test public unadkat</p>,<p>test activity</p>,<p>test chat</p>,<p>private activity</p>,<p>test session initation</p>,<p>join test <span>Your Activity Title</span><span class="required-indicator">*</span><span> </span></p>,<p>test 9</p>
並轉換成這樣的純文本后
asasasa ,test match private ,test activity by m43 ,Test for chat activities ,test 5 for admin ,test ca activity title ,test for video issue ,activity for m43 by c31 ,test activity title community activism By u1 ,test 7 ,test ,chat ,rahul jaykar ,test public unadkat ,test activity ,test chat ,private activity ,test session initation ,join test Your Activity Title* ,test 9
現在我的問題是如何在uitableviewcell中存在的標簽中顯示這些數據。
這是我的表格單元格代碼
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier =@"activismCell";
CAviewCELLCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier forIndexPath:indexPath];
cell.activitytitle.text = (NSString *)[array1 objectAtIndex:indexPath.row];
cell.idline.text = (NSString *)[array3 objectAtIndex:indexPath.row];
cell.issuelabel.text = (NSString *)[array9 objectAtIndex:indexPath.row];
cell.timelabel.text = (NSString *)[array10 objectAtIndex:indexPath.row];
cell.typelabel.text = (NSString *)[array2 objectAtIndex:indexPath.row];
sessid = (NSString *)[array4 objectAtIndex:indexPath.row];
token = (NSString *)[array6 objectAtIndex:indexPath.row];
apikey = (NSString *)[array7 objectAtIndex:indexPath.row];
for (int i=0; i<[array8 count]; i++) {
}
NSLog(@"%@,%@",sessid,token);
NSString *stat =(NSString *)[array2 objectAtIndex:indexPath.row];
NSLog(@"%@",stat);
NSString *trimmedString = [stat stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if([trimmedString isEqualToString:@"Two Way Video Streaming"] || [trimmedString isEqualToString:@"One Way Video Streaming"]) {
[cell.startvideo setHidden:FALSE];
[cell.startvideo setImage:[UIImage imageNamed:@"ca_video.png"] forState:UIControlStateNormal];
[cell.startvideo addTarget:self action:@selector(playAction) forControlEvents:UIControlEventTouchUpInside];
}
else
[cell.startvideo setHidden:TRUE];
return cell;
}
必須在行中使用indexpath在cell.desclabel.text中按順序顯示數據。請幫助我如何執行此操作
通過以下方式從plainText字符串創建數組。
desc1 = [[items valueForKey:@"desc"] componentsJoinedByString:@","];
NSLog(@"%@",desc1);
NSString *itemTitle = [desc1 stringByConvertingHTMLToPlainText];
NSArray *arrNew = [itemTitle componentsSeparatedByString:@","];
現在更改單元格標簽。
cell.desclabel.text = [arrNew objectAtIndex:indexPath.row];
首先,不需要為每個鍵創建單獨的數組array1
, array2
,...。 代替
array1 = [items valueForKey:@"activityTitle"];
// ... and later:
cell.activitytitle.text = (NSString *)[array1 objectAtIndex:indexPath.row];
你可以做
cell.activitytitle.text = items[indexPath.row][@"activityTitle"];
而不是分離和連接“ desc”元素的數組,而使用
NSString *desc1 = items[indexPath.row][@"desc"];
NSString *desc = [desc1 stringByConvertingHTMLToPlainText];
在cellForRowAtIndexPath
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.