在 iOS 中为聊天应用程序在 UITableView 中创建气泡
creating a bubble in UITableView for chat application in iOS
我正在尝试在我的 UITableview
中创建一个 UIBubbleTableView
。我在互联网上搜索了一个示例并尝试了完全相同的事情。但是例子用的是xib,而我用的是storyboard
。
我已经在我的项目中导入了示例中给出的文件。但是当我尝试 运行 那个代码时,它崩溃了说。-
-[UITableView setBubbleDataSource:]: unrecognized selector sent to instance
下面是我试过的。
@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
,但无法连接,因此我不知道如何 'set 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;
在xib/storyboard中添加到class中的UITableView
- UIBubbleTableView
我正在尝试在我的 UITableview
中创建一个 UIBubbleTableView
。我在互联网上搜索了一个示例并尝试了完全相同的事情。但是例子用的是xib,而我用的是storyboard
。
我已经在我的项目中导入了示例中给出的文件。但是当我尝试 运行 那个代码时,它崩溃了说。-
-[UITableView setBubbleDataSource:]: unrecognized selector sent to instance
下面是我试过的。
@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
,但无法连接,因此我不知道如何 'set 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;
在xib/storyboard中添加到class中的UITableView
- UIBubbleTableView