ios - Not able to use UIView in NSObject Xcode -
#import <foundation/foundation.h> typedef enum _nsbubbletype { bubbletypemine = 0, bubbletypesomeoneelse = 1 } nsbubbletype; @interface nsbubbledata : nsobject @property (readonly, nonatomic, strong) nsdate *date; @property (readonly, nonatomic) nsbubbletype type; @property (readonly, nonatomic, strong) uiview *view; @property (readonly, nonatomic) uiedgeinsets insets; @property (nonatomic, strong) uiimage *avatar; - (id)initwithtext:(nsstring *)text date:(nsdate *)date type: (nsbubbletype)type; + (id)datawithtext:(nsstring *)text date:(nsdate *)date type:(nsbubbletype)type; - (id)initwithimage:(uiimage *)image date:(nsdate *)date type:(nsbubbletype)type; + (id)datawithimage:(uiimage *)image date:(nsdate *)date type: (nsbubbletype)type; - (id)initwithview:(uiview *)view date:(nsdate *)date type:(nsbubbletype)type insets:(uiedgeinsets)insets; + (id)datawithview:(uiview *)view date:(nsdate *)date type:(nsbubbletype)type insets:(uiedgeinsets)insets;
below object , .m class #import "nsbubble.h" #import
@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
this table view
#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;
this .m
#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 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]; (int = 0; < 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; (int = 0; < 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 date , 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; }
showing multiple while run project. out of blue .help must appreciated. might problem tableview , datasource think understanding how can implement in this url help.
> ***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 uncaught > exception 'nsinternalinconsistencyexception', reason: 'uitableview > datasource not set'
as can see., error: uitableview datasource not set indicates table view data source not set. have connect table view data source in interface builder.
Comments
Post a Comment