2014-06-16 28 views
0

嗨,我使用code來創建聊天視圖其工作正常,但我需要在點擊添加放大圖像,所以在UIBubbleTableView.m類我添加以下代碼來獲取索引選定的值。UIBubbleTableView從NSBubbleData中獲取didSelectRowAtIndexPath?

- (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

這是不完全清楚你正在嘗試做的事情 - 假設self.bubbleSection是一個數組的NSBubbleData數組,並假設你從這裏使用NSBubbleData https://github.com/AlexBarinov/UIBubbleTableView/blob/master/src/NSBubbleData.h然後它公開一個UIView,而不是一個字符串 – Paulw11

+0

嘿保羅,我怎麼能得到該視圖的價值和猜測它包含文本或圖像? 我需要做的是:如果它包含圖像,然後放大它,如果它包含文本,然後提供翻譯等功能 – iphonemaclover

+0

'view'屬性包含對'UIView'的引用。 – Paulw11

回答

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; 
0

indexPath.row的值是不是字符串。您無法使用%@登錄。嘗試使用用於整數的%i或%li。

+0

感謝您的快速回復,但檢查它的類型轉換已經是字符串... – iphonemaclover

相關問題