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.
Related
I am new in iPhone development. I am using UItableview for showing list.
And able to show all items successfully.
But they changed when I scroll tableview.
Please help me.
Try this code in cellForRowAtIndexPath method of tableview
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
Please give me more information to show your case clearly.
Have a look at this function first because all rows are generated from here!
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleTableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [recipes objectAtIndex:indexPath.row];
return cell;
}
Check whether each row is exist,unless just reuse it later.
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 :
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]?
My application navigation based and view is UITableviewController. I need to add switch control for ON and OFF for particular UIViewtable cell. How to add.
Also a classic, this question has been asked a lot here already. For example, see this question. Search for UITableView and UISwitch to get way more results.
You can add a switch in the -tableView:cellForRowAtIndexPath: method found in the UITableViewDataSource Protocol
- (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...
UISwitch *aSwitch = [[[UISwitch alloc] init] autorelease];
[aSwitch addTarget:self action:#selector(switchChanged:) forControlEvents:UIControlEventValueChanged];
[cell.contentView addSubview:aSwitch];
return cell;
}
How to show a detail disclosure button to the uitableview without using the custom cell. I know its by using the accessoryType: method, but don't know how to implement that..pls help..
// 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] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
return cell;
}
[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;