【问题标题】:creating a bubble in UITableView for chat application in iOS在 UITableView 中为 iOS 中的聊天应用程序创建气泡
【发布时间】:2016-11-14 12:54:44
【问题描述】:

我正在尝试在我的UITableview 中创建一个UIBubbleTableView。我在互联网上搜索了一个示例并尝试了完全相同的事情。但是这个例子使用了xib,我使用的是storyboard。 我已经在我的项目中导入了示例中给出的文件。但是当我尝试运行该代码时,它会崩溃说。-

-[UITableView setBubbleDataSource:]: 无法识别的选择器发送到实例

下面是我尝试过的。

@interface ChatController (){

IBOutlet UIView *textView;
IBOutlet UITextField *textF1;
NSMutableArray *bubbleData1;
IBOutlet UIBubbleTableView *bubbleTbl;
}

-(void)viewDidLoad {
[super viewDidLoad];

//bubble data
NSBubbleData *heyBubble1 = [NSBubbleData dataWithText:@"Hey, halloween is soon" date:[NSDate dateWithTimeIntervalSinceNow:-300] type:BubbleTypeSomeoneElse];
heyBubble1.avatar = [UIImage imageNamed:@"avatar1.png"];

NSBubbleData *photoBubble1 = [NSBubbleData dataWithImage:[UIImage imageNamed:@"halloween.jpg"] date:[NSDate dateWithTimeIntervalSinceNow:-290] type:BubbleTypeSomeoneElse];
photoBubble1.avatar = [UIImage imageNamed:@"avatar1.png"];

NSBubbleData *replyBubble1 = [NSBubbleData dataWithText:@"Wow.. Really cool picture out there. iPhone 5 has really nice camera, yeah?" date:[NSDate dateWithTimeIntervalSinceNow:-5] type:BubbleTypeMine];
replyBubble1.avatar = nil;

bubbleData1 = [[NSMutableArray alloc] initWithObjects:heyBubble1, photoBubble1, replyBubble1, nil];
bubbleTbl.bubbleDataSource = self;
}

应用程序在此行崩溃。 -bubbleTbl.bubbleDataSource = self;

我尝试将“bubbleTbl”插座连接到我的tableview,但无法连接,因此我不知道如何“设置bubbleDataSource”到我的Tableview

谁能帮帮我。任何帮助表示赞赏

编辑-

我已经实现了这个方法并在这个方法上设置了一个断点。但是这个方法永远不会被执行。

- (NSInteger)rowsForBubbleTable:(UIBubbleTableView *)tableView
{

NSLog(@"bubble count %lu",(unsigned long)[bubbleData1 count]);
return [bubbleData1 count];
}

编辑 2-

在气泡中显示视频的代码-

UIEdgeInsets insetss = { .left = 180, .right = 10, .top =10, .bottom = 200 };
NSBubbleData *videodata=[NSBubbleData dataWithView:_playerViewController.view date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeMine insets:(insetss)];
[bubbleData1 addObject:videodata];

编辑 3--

NSString *stringVideoName = @"videobuild.mov";
NSString *stringVideoPath = [[NSBundle mainBundle] pathForResource:stringVideoName ofType:nil];
NSAssert(stringVideoPath, @"Expected not nil video file");

NSURL *urlVideoFile = [NSURL fileURLWithPath:stringVideoPath];
NSAssert(urlVideoFile, @"Expected not nil video url");

_playerViewController = [[AVPlayerViewController alloc] init];
_playerViewController.player = [AVPlayer playerWithURL:urlVideoFile];
_playerViewController.view.frame = CGRectMake(10.0, 0.0, 150.0 , 80.0);  //   self.view.bounds;
_playerViewController.showsPlaybackControls = YES;

【问题讨论】:

    标签: ios uitableview datasource uibubbletableview


    【解决方案1】:

    在课堂上添加 xib/storyboard 到 UITableView - UIBubbleTableView

    【讨论】:

    • UITableView 中有多少行?如果行数 > 0,则检查 cellForRowAtIndexPath 中的单元格
    • 你确定你有关于bubbleTbl的参考吗?如果 bubbleTbl == nil 那么 rowsForBubbleTable 将不会调用。在 bubbleTbl.bubbleDataSource = self 上设置断点并检查。而且这个引用一定要强
    • @MirMiratom - 你能告诉我如何在聊天应用程序中发送图像(图像应该出现在气泡中)
    • UIImage *image = [UIImage imageNamed:@"name_you_image"]; NSBubbleData *photoBubble = [NSBubbleData dataWithImage:image date:[NSDate dateWithTimeIntervalSinceNow:0] type:BubbleTypeSomeoneElse]; [bubbleData addObject:photoBubble]; [bubbleTable reloadData];
    • 感谢您的建议。
    猜你喜欢
    • 1970-01-01
    • 2017-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多