如何为图像和消息创造条件?
Posted
技术标签:
【中文标题】如何为图像和消息创造条件?【英文标题】:how to make condition for image and message? 【发布时间】:2016-04-08 12:09:59 【问题描述】:在我的项目中,我从需要显示图像(如果可用)、消息(如果可用)、点赞数、cmets 数的 facebookSDK 获取数据。
现在在我的数据中有一张图片,但消息不可用。我的字符串显示空消息。现在我需要提出3个条件。
您可以理解我的问题可能与以下代码有关。
self.arrData = nil;
self.arrData = [[NSMutableArray alloc]init];
self.arrData = [result[@"data"] mutableCopy];
for (int i =0; i<self.arrData.count; i++)
NSString *strImage1 = [NSString stringWithFormat:@"%@",[[self.arrData objectAtIndex:i]valueForKey:@"full_picture"]];
NSString *strComment =[NSString stringWithFormat:@"%@", [[self.arrData objectAtIndex:i ]valueForKey:@"message"]];
//in strComment i get @"(null)" message.
NSString *strLike = [NSString stringWithFormat:@"%@", [[[[self.arrData objectAtIndex:i]valueForKey:@"likes"]valueForKey:@"summary"]valueForKey:@"total_count"]];
NSString *strCommentCount = [NSString stringWithFormat:@"%@", [[[[self.arrData objectAtIndex:i]valueForKey:@"comments"]valueForKey:@"summary"]valueForKey:@"total_count"]];
NSString *strTime = [NSString stringWithFormat:@"%@",[[self.arrData objectAtIndex:i]valueForKey:@"created_time"]];
CustomSocialView *imageView1 = [[CustomSocialView alloc] initWithFrame:CGRectMake(0, 0, width, 170)];
[self.vLayout addSubview:imageView1];
//conditions
if (strImage1 == nil)// if image is not available.
NSLog(@"no image");
[imageView1 setContentText:strComment like:strLike comment:strCommentCount time:strTime];
else if ([strCommentCount isEqual: 0]) // if Message is not available // may be here i am wrong.
NSLog(@"no msg");
[imageView1 setImage:strImage1 like:strLike comment:strCommentCount time:strTime];
else
NSLog(@"Both image and msg are available");
[imageView1 setImage:strImage1 setContentText:strComment like:strLike comment:strCommentCount time:strTime];
现在我很困惑如何为我的代码设置条件。
请帮帮我。
谢谢。
【问题讨论】:
您想将您的响应数据放到图像或标签上吗? 什么意思 "isEqual: 0" 你正在传递一个字符串值,你怎么能将字符串值与整数值进行比较。尝试 @"" 而不是 0 【参考方案1】:试试这个:
for (int i = 0; i<self.arrData.count; i++)
//your code
if (strImage1 != nil && [strCommentCount intValue] != 0 )// if image is not available.
NSLog(@"Both image and msg are available");
[imageView1 setImage:strImage1 setContentText:strComment like:strLike comment:strCommentCount time:strTime];
else
if ([strCommentCount intValue] != 0)
NSLog(@"no image");
[imageView1 setContentText:strComment like:strLike comment:strCommentCount time:strTime];
else
NSLog(@"no msg");
[imageView1 setImage:strImage1 like:strLike comment:strCommentCount time:strTime];
【讨论】:
以上是关于如何为图像和消息创造条件?的主要内容,如果未能解决你的问题,请参考以下文章