views:

767

answers:

1

Hi,

In my iphone application Uitable having So many cells with Text.The Text size is more than the width of the device.So, how can i wrap the text in cell and display the text in the different Lines or devide it in the lines?

if anybody has any solution or any useful code or any other useful link,which would be appreciated.

Thanks,

Mishal Shah

+1  A: 

You can add a UILabel as a subview of a cell in a

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

method. Then set its lineBreakMode and numberOfLines properties as you want. The code must look something like this:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tID];
  if (cell == nil) {
 cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:tID] autorelease];
 }
else{
       UIView *tView = [cell viewWithTag:100];
 [tView removeFromSuperview];
}
UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 90, 50)];
label.tag = 100;
label.numberOfLines = 2;
label.lineBreakMode = UILineBreakModeWordWrap;
label.text = @"Putyourverylongcelltexthere";
[cell addSubview:label];
[label release];
Vladimir