cell.detaillabel's text not shown - iphone

I have a tableView in which I need to show textlabel and detailtextlabel.
But detailtextlabel is not shown.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier=#"Cell";
UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil){
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
}
NSMutableDictionary *d2 =[[NSMutableDictionary alloc]initWithDictionary:[autocompleteUrls objectAtIndex:indexPath.row]];
cell.textLabel.text = [NSString stringWithFormat:#"%#",[d2 valueForKey:#"FLName"]];
cell.detailTextLabel.text=#"Id";
cell.textLabel.font=[UIFont boldSystemFontOfSize:12];
cell.textLabel.numberOfLines=0;
return cell;
}
But detailtextlabel is not shown, why?

You use UITableViewCellStyleDefault but you have to use UITableViewCellStyleSubtitle
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]autorelease];

I usually use UITableViewCellStyleValue1 in this case
[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]

To give you answer in details :

Related

Where should font settings for cell.titleLabel go in the cellForRowAtIndexPath: method?

Should I put set the font of a cell.titleLabel in the cell == nil portion of the cellForRowAtIndexPath: method? or after? I'm also adding some labels and a UIImage programmatically. The UIImage doesn't change but the value of the labels does.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = #"identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
[cell.titleLabel setFont:[UIFont fontWithName: #"Asap-Bold" size: 15.0f]];
[cell.descriptionLabel setFont:[UIFont fontWithName: #"Asap-Regular" size: 10.0f]];
}
**// or should it go here?**
return cell;
}
thanks for any help.
You are right setting font in braces because this code should be executed once. Outside braces should be the code that getting access to your data source e.g. when you doing smth like this
cell.label.text = [self.dataArray objectAtIndex:i];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = #"identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
//executed once per cell
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease];
[cell.titleLabel setFont:[UIFont fontWithName: #"Asap-Bold" size: 15.0f]];
[cell.descriptionLabel setFont:[UIFont fontWithName: #"Asap-Regular" size: 10.0f]];
}
//Executed every time
cell.label.text = [self.dataArray objectAtIndex:i];
return cell;
}
if cell font is independent of row number then it always have to go inside if(cell == nil).

UITableView detailTextLabel - iphone development

why is "detailTextLabel" not working anymore?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
cell.textLabel.text=[listData objectAtIndex:[indexPath row]];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
cell.detailTextLabel.text=#"hi";
return cell;
}
Try to change the style of the cell, use this code while initializing the cell
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
For more information about the cell styles look at the apple's class reference
You've chosen a cell style UITableViewCellStyleDefault that does not support a detailTextLabel
Try using a different style.
edit
You choose a style in the initWithStyle:reuseIdentifier; method. Have a look at the UITableViewCell docs which describes the available cell styles.

UITableView backgroundview not working on text area

I'm trying to customize how my UITableView looks by setting the backgroundView with an UIImageView, but is not working properly as you can see in the image. (only works for the accessoryType and at the start of the row before the text.)
Can anybody help me with this?
My code:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell.
NSDictionary *lineaAutobus = [buscamionService objectAtIndex:indexPath.row];
NSString *lineaAutobusNombre = [lineaAutobus objectForKey:#"nombre_lineaAutobus"];
[cell setBackgroundView:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tableViewCellBg.png"]] autorelease]];
cell.textLabel.text = lineaAutobusNombre;
return cell;
}
https://www.dropbox.com/s/ubok76ipshei931/Screen%20shot%202011-05-20%20at%206.25.29%20PM.png
Perhaps you need to set the backgroundColor of the textLabel to [UIColor clearColor]?

How to show disclosure indicator while cells are in edit mode?

I have a UITableView that can be edited. I am displaying cells as such:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell...
STWatchList *mySTWatchList;
mySTWatchList = [items objectAtIndex:indexPath.row];
cell.textLabel.text = mySTWatchList.watchListName;
return cell;
}
When the user is editing, I would like to show the disclosure indicator. How can I accomplish this?
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
if (indexPath.row==0)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}

cell.detailTextLabel.text not working... why

Using the following code I am getting the text.label but not the detailTextLabel.text. The NSLog is displaying correctly.
cell.textLabel.text = [eventLabels objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [eventFields objectAtIndex:indexPath.row]];
NSLog(#"%#", [eventFields objectAtIndex:indexPath.row]);
I also tried...
cell.detailTextLabel.text = [NSString stringWithFormat:#"%#", [eventFields objectAtIndex:indexPath.row]];
I have not had problems with this before. Any suggestions?
John
Make sure you're using an appropriate UITableViewCellStyle with this (anything but UITableViewCellStyleDefault should thus work). The cell's style is specified when you initialize it.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
}
Do remember to change to UITableViewCellStyleSubtitle
If you choose style UITableViewCellStyleSubtitle , your detailTextLabel.text will show
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] ;
UITableView Source