我想看到文本到达单元格的末尾,然后开始一个新行.
我的代码现在看起来像这样.
@implementation CRHCommentSection@synthesize observationtable; NSArray *myArray; - (voID)vIEwDIDLoad{ myArray = [CRHVIEwControllerScript theArray]; NSLog(@"%@",myArray); //NSArray* paths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:0 inSection:1]]; //[observationtable insertRowsAtIndexPaths:paths withRowAnimation:UItableVIEwRowAnimationtop]; [observationtable reloadData]; [super vIEwDIDLoad];// Do any additional setup after loading the vIEw.}- (NSInteger)numberOfSectionsIntableVIEw:(UItableVIEw *)tableVIEw { // Return the number of sections. NSLog(@" in method 1"); return 1;}- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section { NSLog(@" in method 2");// Return the number of rows in the section.return [myArray count];}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath {NSLog(@" in method 3");static Nsstring *CellIDentifIEr = @"Cell";UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr];if (cell == nil) { cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwStylePlain reuseIDentifIEr:CellIDentifIEr];}cell.textLabel.text = [myArray objectAtIndex:indexPath.row];//cell.textLabel.text = @"Label"; return cell;}
我还发现了一些其他人为多个单元格编写的代码但却不知道如何根据数组中字符串的长度自动编写代码.
static Nsstring *CellIDentifIEr = @"MyCell"; UItableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:CellIDentifIEr];if (cell == nil) { cell = [[[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleValue2 reuseIDentifIEr:CellIDentifIEr] autorelease];}cell.textLabel.text = @"Label';cell.detailTextLabel.text = @"Multi-line\nText";cell.detailTextLabel.numberOflines = 2;cell.detailTextLabel.lineBreakMode = UIlineBreakModeWorDWrap;
他们说你还需要为多线单元返回一个合适的高度,并且(44.0(numberOflines – 1)* 19.0)的高度应该可以正常工作.
有没有人有任何想法如何做到这一点?
谢谢.
解决方法 您需要使用以下方法- (CGfloat)tableVIEw:(UItableVIEw *)tableVIEw heightForRowAtIndexPath:(NSIndexPath *)indexPath{ // this method is called for each cell and returns height Nsstring * text = @"Your very long text"; CGSize textSize = [text sizeWithFont:[UIFont systemFontOfSize: 14.0] forWIDth:[tableVIEw frame].size.wIDth - 40.0 lineBreakMode:NSlineBreakByWorDWrapPing]; // return either default height or height to fit the text return textSize.height < 44.0 ? 44.0 : textSize.height;}- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static Nsstring * cellIDentifIEr = @"YourtableCell"; UItableVIEwCell * cell = [tableVIEw dequeueReusableCellWithIDentifIEr:cellIDentifIEr]; if (cell == nil) { cell = [[UItableVIEwCell alloc] initWithStyle:UItableVIEwCellStyleValue1 reuseIDentifIEr:cellIDentifIEr]; [[cell textLabel] setNumberOflines:0]; // unlimited number of lines [[cell textLabel] setlineBreakMode:NSlineBreakByWorDWrapPing]; [[cell textLabel] setFont:[UIFont systemFontOfSize: 14.0]]; } [[cell textLabel] setText:@"Your very long text"]; return cell;}总结
以上是内存溢出为你收集整理的objective-c – 使所有文本显示在UITableView单元格中全部内容,希望文章能够帮你解决objective-c – 使所有文本显示在UITableView单元格中所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)