您好我正在使用code创建聊天视图,它的工作正常,但我需要在点击时添加放大图像,所以在UIBubbleTableView.m类中我添加了以下代码以获取索引选择值。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"value of index=%@",[NSString stringWithFormat:@"%d",indexPath.row]);
NSLog(@"value of selected section=%@",[NSString stringWithFormat:@"%@", [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row - 1]]);
}
它提供以下输出:
所选部分的值=
我如何从上面的NSBubbleData获取文本或图像
此代码中的数据传递具有以下格式
//for photo
NSBubbleData *photoBubblenew = [NSBubbleData dataWithImage:image date:[NSDate dateWithTimeIntervalSinceNow:-0] type:BubbleTypeMine];
//for text
NSBubbleData * TextBubble = [NSBubbleData dataWithText:@"Hi,Check out Iphonelover" date:[NSDate dateWithTimeIntervalSinceNow:-300] type:BubbleTypeSomeoneElse];
答案 0 :(得分:1)
将标签贴在这里...
-(id)initWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type
{
UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
CGSize size = [(text ? text : @"") sizeWithFont:font constrainedToSize:CGSizeMake(220, 9999) lineBreakMode:NSLineBreakByWordWrapping];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
label.numberOfLines = 0;
label.lineBreakMode = NSLineBreakByWordWrapping;
label.text = (text ? text : @"");
label.font = font;
label.backgroundColor = [UIColor clearColor];
label.tag=100;
UIEdgeInsets insets = (type == BubbleTypeMine ? textInsetsMine : textInsetsSomeone);
return [self initWithView:label date:date type:type insets:insets];}
然后在这里获取价值
NSBubbleData *bubble=Chat_DATA [indexPath.row];
UIView *view=bubble.view;
UILabel *LBL=(UILabel*) [view viewWithTag:100];
NSString *msg=LBL.text;
答案 1 :(得分:0)
indexPath.row的值不是字符串。您无法使用%@进行日志记录。尝试使用%i或%li,它们用于整数。