Note that there are some explanatory texts on larger screens.

plurals
  1. POsqlite formatting with iphone tableview's label
    primarykey
    data
    text
    <p>I am displaying data from database in table view. In table view cell contains label of dynamic height according to database value.Suppose I want to display description of any city from database in table view with label in cell, I manually added description in database.My problem is that some time label is not displaying full description because width of label in 320 px for i phone and in sqlite database it is more than 320.In that case all the formatting got disturbed in iphone.I have to change spacing or tabs in database then test in iphone.I have lot of entries and this is very time consuming..And If I give lot of spacing in database then Label will display blank space after description is completed. Is there any way to solve this formatting problem.</p> <p>This is my code</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)atableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //label to hold description of city UILabel *label = nil; //cell identifier for each section oftable static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [atableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc]initWithFrame:CGRectZero reuseIdentifier:@"Cell"]autorelease]; //label initialization label = [[UILabel alloc]initWithFrame:CGRectZero]; [label setLineBreakMode:UILineBreakModeWordWrap]; [label setMinimumFontSize:kFontSize]; [label setNumberOfLines:0]; [label setFont:[UIFont fontWithName:@"Futura" size:13.0]]; label.autoresizingMask = UIViewAutoresizingFlexibleWidth; [label setTag:1]; //adding label to cell's content view [[cell contentView]addSubview:label]; [label release]; } cell.selectionStyle = UITableViewCellSelectionStyleNone; // text to display in label in cell NSString *text = city.Description; CGSize constraint = CGSizeMake(kCellContentWidth - (kCellContentMargin * 2), 20000.0f); CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:kFontSize] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; if (!label) label = (UILabel*)[cell viewWithTag:1]; [label setText:text]; [label setFrame:CGRectMake(kCellContentMargin, kCellContentMargin, kCellContentWidth - (kCellContentMargin *4), MAX(size.height, 44.0f))]; return cell; } //Dynamic size label according to description - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *text = city.Description; CGSize constraint = CGSizeMake(kCellContentWidth - (kCellContentMargin *2), 20000.0f); CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:kFontSize] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap]; CGFloat height = MAX(size.height , 44.0f); return height + (kCellContentMargin *2); //returning height of label with font size and constaraint size } </code></pre> <p>My model class for city is</p> <pre><code> @interface City : NSManagedObject { } @property (nonatomic, retain) NSString * Description; @property (nonatomic, retain) NSString * Name; @property (nonatomic, retain) NSData * Image; @property (nonatomic, retain) NSSet* cityToRestaurant; @property (nonatomic, retain) NSSet* cityToHotel; @property (nonatomic, retain) NSSet* cityToPlaces; @end @interface City (CoreDataGeneratedAccessors) - (void)addCityToRestaurantObject:(NSManagedObject *)value; - (void)removeCityToRestaurantObject:(NSManagedObject *)value; - (void)addCityToRestaurant:(NSSet *)value; - (void)removeCityToRestaurant:(NSSet *)value; - (void)addCityToHotelObject:(NSManagedObject *)value; - (void)removeCityToHotelObject:(NSManagedObject *)value; - (void)addCityToHotel:(NSSet *)value; - (void)removeCityToHotel:(NSSet *)value; - (void)addCityToPlacesObject:(NSManagedObject *)value; - (void)removeCityToPlacesObject:(NSManagedObject *)value; - (void)addCityToPlaces:(NSSet *)value; - (void)removeCityToPlaces:(NSSet *)value; </code></pre> <p>And implementation file</p> <pre><code> #import "City.h" @implementation City @dynamic Description; @dynamic Name; @dynamic Image; @dynamic cityToRestaurant; @dynamic cityToHotel; @dynamic cityToPlaces; @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload