Ios 无法在NSObject Xcode中使用UIView
这是我的桌面视图Ios 无法在NSObject Xcode中使用UIView,ios,xcode,Ios,Xcode,这是我的桌面视图 @implementation NSBubble @synthesize datee,vieww,insetss,typee; #pragma mark - Text bubble const UIEdgeInsets textInsetsMine = {5, 10, 11, 17}; const UIEdgeInsets textInsetsSomeone = {5, 15, 11, 10}; + (id)dataWithText:(NSString *)text d
@implementation NSBubble
@synthesize datee,vieww,insetss,typee;
#pragma mark - Text bubble
const UIEdgeInsets textInsetsMine = {5, 10, 11, 17};
const UIEdgeInsets textInsetsSomeone = {5, 15, 11, 10};
+ (id)dataWithText:(NSString *)text date:(NSDate *)date type:(NSBubbleType)type
{
return [[NSBubble alloc] initWithText:text date:date type:type];
}
- (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];
UIEdgeInsets insets = (type == BubbleTypeMine ? textInsetsMine : textInsetsSomeone);
return [self initWithView:label date:date type:type insets:insets];
}
#pragma mark - Custom view bubble
+ (id)dataWithView:(UIView *)view date:(NSDate *)date type:(NSBubbleType)type insets:(UIEdgeInsets)insets
{
return [[NSBubble alloc] initWithView:view date:date type:type insets:insets];
}
- (id)initWithView:(UIView *)view date:(NSDate *)date type:(NSBubbleType)type insets:(UIEdgeInsets)insets
{
self = [super init];
if (self)
{
vieww = view;
datee = date;
typee = type;
insetss = insets;
}
return self;
}
@end
#导入
#导入“HeaderDataSource.h”
#导入“NSBubbleTblCell.h”
@接口NSBubbleTblView:UITableView
@属性(非原子,赋值)IBOutlet id bubbleDataSource;
@属性(非原子)NSTimeInterval snapInterval;
-(void)滚动BubbleViewToBottoManimated:(BOOL)动画;
这是
#import <UIKit/UIKit.h>
#import "HeaderDataSource.h"
#import "NSBubbleTblCell.h"
@interface NSBubbleTblView : UITableView <UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, assign) IBOutlet id<UIBubbleTableViewDataSource> bubbleDataSource;
@property (nonatomic) NSTimeInterval snapInterval;
- (void) scrollBubbleViewToBottomAnimated:(BOOL)animated;
#导入“NSBubbleTblView.h”
#导入“NSBubble.h”
#导入“NSBubbleTblHeaderCell.h”
@接口NSBubbleTblView()
@属性(非原子,保留)NSMutableArray*bubbleSection;
@结束
@NSBubbleTblView的实现
@综合数据源、snapInterval、bubbleSection;
#pragma标记-初始化器
-(void)初始化器
{
//UITableView属性
self.backgroundColor=[UIColor clearColor];
self.separatorStyle=UITableViewCellSeparatorStyleNone;
断言(self.style==UITableViewStylePlain);
self.delegate=self;
self.dataSource=self;
//UIBubbleTableView默认属性
self.snapInterval=120;
}
-(id)init
{
self=[super init];
if(self)[自初始化器];
回归自我;
}
-(id)initWithCoder:(NSCoder*)aDecoder
{
self=[super initWithCoder:aDecoder];
if(self)[自初始化器];
回归自我;
}
-(id)initWithFrame:(CGRect)帧
{
self=[super initWithFrame:frame];
if(self)[自初始化器];
回归自我;
}
-(id)initWithFrame:(CGRect)框架样式:(UITableViewStyle)样式
{
self=[super initWithFrame:frame-style:UITableViewStylePlain];
if(self)[自初始化器];
回归自我;
}
#pragma标记-覆盖
-(void)重新加载数据
{
self.showsVerticalScrollIndicator=否;
self.showshorizontalscrolindicator=否;
NSLog(@“%@”,气泡切片);
//清理
self.bubbleSection=nil;
//加载新数据
整数计数=0;
self.bubbleSection=[[NSMutableArray alloc]init];
if(self.bubbleDataSource&&(count=[self.bubbleDataSource行sfobbleTable:self])>0)
{
NSMutableArray*bubbleData=[[NSMutableArray alloc]initWithCapacity:count];
for(int i=0;iself.snapInterval)
{
currentSection=[[NSMUTABLEARRY alloc]init];
[self.bubbleSection addObject:currentSection];
}
[currentSection addObject:数据];
last=data.datee;
}
}
}
[超级重载数据];
}
#pragma标记-UITableViewDataSource实现
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
int result=[self.bubbleSection count];
返回结果;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
返回[[self.bubbleSection objectAtIndex:section]count];
}
-(float)tableView:(UITableView*)表视图行高度索引路径:(NSIndexPath*)索引路径
{
//标题
if(indexPath.row==0)
{
返回[NSBubbleTblHeaderCell高度];
}
NSBubble*data=[[self.bubbleSection objectAtIndex:indexath.section]objectAtIndex:indexath.row-1];
返回data.insetss.top+data.vieww.frame.size.height+data.insetss.bottom;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
//带有日期和时间的标题
if(indexPath.row==0)
{
静态NSString*cellId=@“tblBubbleHeaderCell”;
NSBubbleTblHeaderCell*单元格=[tableView dequeueReusableCellWithIdentifier:cellId];
NSBubble*data=[[self.bubbleSection objectAtIndex:indexath.section]objectAtIndex:0];
if(cell==nil)cell=[[NSBubbleTblHeaderCell alloc]init];
cell.date=data.datee;
返回单元;
}
//标准气泡
静态NSString*cellId=@“tblBubbleCell”;
NSBubbleTblCell*单元格=[tableView dequeueReusableCellWithIdentifier:cellId];
NSBubble*data=[[self.bubbleSection objectAtIndex:indexath.section]objectAtIndex:indexath.row-1];
如果(单元格==nil)
cell=[[NSBubbleTblCell alloc]init];
cell.data=数据;
返回单元;
}
在运行项目时显示多个。这就像是突如其来的。必须感谢你的帮助。他们可能在tableview及其数据源方面存在一些问题,我想我已经理解了如何在有人帮助的情况下在这个url中实现
您需要导入
。它添加了必要的UIImage、UITableView、UIView等
#import "NSBubbleTblView.h"
#import "NSBubble.h"
#import "NSBubbleTblHeaderCell.h"
@interface NSBubbleTblView ()
@property (nonatomic, retain) NSMutableArray *bubbleSection;
@end
@implementation NSBubbleTblView
@synthesize dataSource,snapInterval,bubbleSection;
#pragma mark - Initializators
- (void)initializator
{
// UITableView properties
self.backgroundColor = [UIColor clearColor];
self.separatorStyle = UITableViewCellSeparatorStyleNone;
assert(self.style == UITableViewStylePlain);
self.delegate = self;
self.dataSource = self;
// UIBubbleTableView default properties
self.snapInterval = 120;
}
- (id)init
{
self = [super init];
if (self) [self initializator];
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) [self initializator];
return self;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) [self initializator];
return self;
}
- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
self = [super initWithFrame:frame style:UITableViewStylePlain];
if (self) [self initializator];
return self;
}
#pragma mark - Override
- (void)reloadData
{
self.showsVerticalScrollIndicator = NO;
self.showsHorizontalScrollIndicator = NO;
NSLog(@"%@",bubbleSection);
// Cleaning up
self.bubbleSection = nil;
// Loading new data
int count = 0;
self.bubbleSection = [[NSMutableArray alloc] init];
if (self.bubbleDataSource && (count = [self.bubbleDataSource rowsForBubbleTable:self]) > 0)
{
NSMutableArray *bubbleData = [[NSMutableArray alloc] initWithCapacity:count];
for (int i = 0; i < count; i++)
{
NSObject *object = [self.bubbleDataSource bubbleTableView:self dataForRow:i];
assert([object isKindOfClass:[NSBubble class]]);
[bubbleData addObject:object];
[bubbleData sortUsingComparator:^NSComparisonResult(id obj1, id obj2)
{
NSBubble *bubbleData1 = (NSBubble *)obj1;
NSBubble *bubbleData2 = (NSBubble *)obj2;
return [bubbleData1.datee compare:bubbleData2.datee];
}];
NSDate *last = [NSDate dateWithTimeIntervalSince1970:0];
NSMutableArray *currentSection = nil;
for (int i = 0; i < count; i++)
{
NSBubble *data = (NSBubble *)[bubbleData objectAtIndex:i];
if ([data.datee timeIntervalSinceDate:last] > self.snapInterval)
{
currentSection = [[NSMutableArray alloc] init];
[self.bubbleSection addObject:currentSection];
}
[currentSection addObject:data];
last = data.datee;
}
}
}
[super reloadData];
}
#pragma mark - UITableViewDataSource implementation
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
int result = [self.bubbleSection count];
return result;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[self.bubbleSection objectAtIndex:section] count];
}
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Header
if (indexPath.row == 0)
{
return [NSBubbleTblHeaderCell height];
}
NSBubble *data = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row - 1];
return data.insetss.top + data.vieww.frame.size.height + data.insetss.bottom;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Header with date and time
if (indexPath.row == 0)
{
static NSString *cellId = @"tblBubbleHeaderCell";
NSBubbleTblHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
NSBubble *data = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:0];
if (cell == nil) cell = [[NSBubbleTblHeaderCell alloc] init];
cell.date = data.datee;
return cell;
}
// Standard bubble
static NSString *cellId = @"tblBubbleCell";
NSBubbleTblCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
NSBubble *data = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row - 1];
if (cell == nil)
cell = [[NSBubbleTblCell alloc] init];
cell.data = data;
return cell;
}
如您所见,此错误:未设置UITableView数据源表示未设置表视图数据源。您必须将表视图与interface builder中的数据源连接。缺少UIKit导入?它显示了另一个错误,如-[NSBubbleTblView\u createPreparedCellForGlobalRow:WithindXPath:willDisplay:],/SourceCache/UIKit\u Sim/UIKit-3318.16.14/UITableView.m:9269 2015-07-27 16:53:23.807 Hansel[6740:143046]***由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“未设置UITableView数据源”我已使用数据源和表视图单元格创建了自定义表视图,因此当我运行项目时,它会显示上述错误。这是另一个错误。这是运行时的错误。您显示的代码中没有“UITableView”。我们猜不出是怎么回事。我知道,但在-[NSBubbleTblView]中运行程序***断言失败时,它会出现另一个异常,createPreparedCellForGlobalRow:withIndexPath:willDisplay:,/SourceCache
#import "NSBubbleTblView.h"
#import "NSBubble.h"
#import "NSBubbleTblHeaderCell.h"
@interface NSBubbleTblView ()
@property (nonatomic, retain) NSMutableArray *bubbleSection;
@end
@implementation NSBubbleTblView
@synthesize dataSource,snapInterval,bubbleSection;
#pragma mark - Initializators
- (void)initializator
{
// UITableView properties
self.backgroundColor = [UIColor clearColor];
self.separatorStyle = UITableViewCellSeparatorStyleNone;
assert(self.style == UITableViewStylePlain);
self.delegate = self;
self.dataSource = self;
// UIBubbleTableView default properties
self.snapInterval = 120;
}
- (id)init
{
self = [super init];
if (self) [self initializator];
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) [self initializator];
return self;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) [self initializator];
return self;
}
- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
self = [super initWithFrame:frame style:UITableViewStylePlain];
if (self) [self initializator];
return self;
}
#pragma mark - Override
- (void)reloadData
{
self.showsVerticalScrollIndicator = NO;
self.showsHorizontalScrollIndicator = NO;
NSLog(@"%@",bubbleSection);
// Cleaning up
self.bubbleSection = nil;
// Loading new data
int count = 0;
self.bubbleSection = [[NSMutableArray alloc] init];
if (self.bubbleDataSource && (count = [self.bubbleDataSource rowsForBubbleTable:self]) > 0)
{
NSMutableArray *bubbleData = [[NSMutableArray alloc] initWithCapacity:count];
for (int i = 0; i < count; i++)
{
NSObject *object = [self.bubbleDataSource bubbleTableView:self dataForRow:i];
assert([object isKindOfClass:[NSBubble class]]);
[bubbleData addObject:object];
[bubbleData sortUsingComparator:^NSComparisonResult(id obj1, id obj2)
{
NSBubble *bubbleData1 = (NSBubble *)obj1;
NSBubble *bubbleData2 = (NSBubble *)obj2;
return [bubbleData1.datee compare:bubbleData2.datee];
}];
NSDate *last = [NSDate dateWithTimeIntervalSince1970:0];
NSMutableArray *currentSection = nil;
for (int i = 0; i < count; i++)
{
NSBubble *data = (NSBubble *)[bubbleData objectAtIndex:i];
if ([data.datee timeIntervalSinceDate:last] > self.snapInterval)
{
currentSection = [[NSMutableArray alloc] init];
[self.bubbleSection addObject:currentSection];
}
[currentSection addObject:data];
last = data.datee;
}
}
}
[super reloadData];
}
#pragma mark - UITableViewDataSource implementation
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
int result = [self.bubbleSection count];
return result;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[self.bubbleSection objectAtIndex:section] count];
}
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Header
if (indexPath.row == 0)
{
return [NSBubbleTblHeaderCell height];
}
NSBubble *data = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row - 1];
return data.insetss.top + data.vieww.frame.size.height + data.insetss.bottom;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Header with date and time
if (indexPath.row == 0)
{
static NSString *cellId = @"tblBubbleHeaderCell";
NSBubbleTblHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
NSBubble *data = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:0];
if (cell == nil) cell = [[NSBubbleTblHeaderCell alloc] init];
cell.date = data.datee;
return cell;
}
// Standard bubble
static NSString *cellId = @"tblBubbleCell";
NSBubbleTblCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
NSBubble *data = [[self.bubbleSection objectAtIndex:indexPath.section] objectAtIndex:indexPath.row - 1];
if (cell == nil)
cell = [[NSBubbleTblCell alloc] init];
cell.data = data;
return cell;
}
> ***Assertion failure in -[NSBubbleTblView
> _createPreparedCellForGlobalRow:withIndexPath:willDisplay:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:9269 2015-07-27
> 16:53:23.807 Hansel[6740:143046] *** Terminating app due to uncaught
> exception 'NSInternalInconsistencyException', reason: 'UITableView
> dataSource is not set'