I'm not seeing the text for my UITableView show up.. in fact the TableView doesn't appear to be on the screen at all because I cannot select the empty rows.
Strangely, my log in cellForRowAtIndexPath shows up ok with the expected data - I just don't see any on the screen.
-(void)bindFriendsToTable:(NSArray *)friends{
NSLog(#"friends : %#",friends);
[sections removeAllObjects];
[sectionRows removeAllObjects];
[sections addObject:#"Friends"];
[sectionRows setObject:friends forKey:#"Friends"];
[self.tableView reloadData];
HideActivityIndicator();
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *cellsection = [sections objectAtIndex:indexPath.section];
NSArray *rowsInSection = [sectionRows valueForKey:cellsection];
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.font = [UIFont fontWithName:#"Helvetica" size:14];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.textLabel.text = [rowsInSection objectAtIndex:indexPath.row];
NSLog(#"%#",cell.textLabel.text);
return cell;
}
I'm inheriting from a base class which is a UITableViewController, as I have for a dozen other screens in the project. Any idea why I'm not seeing the tableView?
Is your font colour the same as your background colour? If you set the accessoryType to a checkmark does it display?
cell.accessoryType = UITableViewCellAccessoryCheckmark;
Do you have any header sections? If so make sure you return a value for heightForHeaderInSection:
-(float)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 66;
}
i think u should remove
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
and then try it.
and display the other static string in the cell to check the problem.
Related
I am using tableView grouped Style. my DisclosureButton is not shown in my table cell.what I am missing?
THANKS
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
NSArray *listData =[self.tableContents objectForKey:[self.sortedKeys objectAtIndex:[indexPath section]]];
UITableViewCell * cell = [tableView
dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
// cell.backgroundColor=[UIColor brownColor];
cell.accessoryType =UITableViewCellAccessoryDetailDisclosureButton;
return cell;
}
Your table seems to be in editing state. You should set the accessoryType in editing mode.
cell.editingAccessoryType=UITableViewCellAccessoryDetailDisclosureButton;
UITableView hide the accessory button in editing mode.
So if you want to display it, you will need to customize the UITableViewCell.
Or you can do it like the answer given by
Vito Limandibhrata
I have a working table view on my iphone app, and am implementing a second view using navigationController.
But when I try to select a cell on the initial view, it does not respond i.e. no highlighting in blue, no selection.
Can anyone suggest what I might have missed, or what is responsible for actually selecting the cell when the user taps it?
OK thanks for your suggestions - still no luck. here is my code:
- (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 setSelectionStyle: UITableViewCellSelectionStyleBlue];
UIView *selectionView = [[[UIView alloc] init] autorelease];
selectionView.backgroundColor =[UIColor redColor];
cell.selectedBackgroundView = selectionView;
}
// format text
cell.textLabel.font = [UIFont fontWithName:#"Arial" size:12];
cell.textLabel.text = [tableArray objectAtIndex:indexPath.row];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//NSUInteger row = indexPath.row;
//[DetailView selectRowAtIndexPath:indexPath animated:YES];
//UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath.row];
//[cell setSelectionStyle: UITableViewCellSelectionStyleBlue];
DetailView *detailView = [[DetailView alloc] initWithNibName:#"DetailView" bundle:nil];
[self.navigationController pushViewController:detailView animated:YES];
[DetailView release];
}
May be you have done this line of code in cellForRowatIndexPath::
cell.selectionStyle = UITableViewCellSelectionStyleNone;
If yes, then replace it with either of these:
cell.selectionStyle = UITableViewCellSelectionStyleGray;
or
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
Without looking at your code I would say you have to add this line in your cellForRowAtIndexPath delegate method.
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
And also you have to implement this delegate method which gets called when you tap on cell of UITableView..
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
}
I have created a custom table for the rootViewController of a split view application so that the selected row expands and shows as a sub-table (showing main menu and sub menu ). The first row of the sub-table should show the particular main menu item of the sub-table.I'm fetching the main menu items from another class.
The problem is that the first row for the sub table is showing blank for me.Using NSLog, I checked the value of variable just before assigning it to the cell and even after assigning the value to the cell, i checked the text value in the cell using cell.textLabel.text. I'm getting the value in the console every time, but the row is still blank!!!
Row is showing the value if I'm hard coding it with any value!!!
Note:TableView is showing values for remaining rows.
Anybody can help me?? Thanks in advance...and sorry for my poor English..
EDIT: In the rootViewController:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
tableView.separatorColor=[UIColor grayColor];
if (sectionopen[indexPath.row]) {
accordianTable *cell1;
cell1=(accordianTable *)[tableView dequeueReusableCellWithIdentifier:#"cell1"];
if (cell1 == nil) {
cell1 = [[[accordianTable alloc] initWithFrame:CGRectZero reuseIdentifier:#"cell1"] autorelease];
}
cell1.selectionStyle=UITableViewCellSelectionStyleNone;
return cell1;
} else {
//tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
static NSString *CellIdentifier = #"CellIdentifier";
// Dequeue or create a cell of the appropriate type.
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
}
// Configure the cell.
cell.textLabel.text=[UIAppDelegate.mainMenu objectAtIndex:indexPath.row];
return cell;
}
}
(void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
accordianTable *acc = [[accordianTable alloc]init];
acc.titl=[UIAppDelegate.mainMenu objectAtIndex:indexPath.row];
[acc.subTable reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
///turn them all off
sectionopen[0]=NO;
sectionopen[1]=NO;
sectionopen[2]=NO;
sectionopen[3]=NO;
///open this one
sectionopen[indexPath.row]=YES;
///animate the opening and expand the row
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
UIViewController *localdetailViewController = nil;
}
In the custom cell class (accordianTable):
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Number of rows is the number of time zones in the region for the specified section.
return [UIAppDelegate.subMenu count]+1;//including title and sub menu
}
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier] autorelease];
}
switch (indexPath.row)
{
case 0:
NSLog(#"text is >> %#",titl);
cell.textLabel.text=titl;
NSLog(#"text is >> %#",cell.textLabel.text);
cell.textLabel.textColor=[UIColor whiteColor];
cell.contentView.backgroundColor=[UIColor blackColor];
cell.textLabel.backgroundColor=[UIColor blackColor];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
break;
default:
int Row=indexPath.row;
Row--;
cell.textLabel.text=[UIAppDelegate.subMenu objectAtIndex:Row];
cell.textLabel.textColor=[UIColor orangeColor];
cell.textLabel.textAlignment=UITextAlignmentCenter;
cell.selectionStyle=UITableViewCellSelectionStyleNone;
break;
}
return cell;
}
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]?
I am trying to customize the font of a UITableViewCell using the following code for when the tableview is populated.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:MyIdentifier];
}
// Set up the cell
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString *temp = [[NSString alloc] initWithString:[[stories objectAtIndex: storyIndex] objectForKey: #"title"]];
cell.textLabel.text = temp;
[[cell textLabel] setTextColor:[UIColor colorWithRed:154.0/255.0 green:14.0/255.0 blue:2.0/255.0 alpha:1]];
[[cell textLabel] setFont:[UIFont systemFontOfSize:12.0]];
return cell;
}
For the life of me I don't know why it won't change the font! Also the above code works fine if I hard code in what the cell text is such as cell.textLabel.text = #"TEST";
Any suggestions? Thanks!
First, you should autorelease your cell. You are leaking memory like crazy presently.
Second, you should update the font in tableView:willDisplayCellForRow:atIndexPath:. If you are using a standard table view, it will make changes to your cells (at random times) and you will need to do things like font changes, background color, etc in the tableView:willDisplayCellForRow:atIndexPath: instead of in the data source method.
See also this thread: What is -[UITableViewDelegate willDisplayCell:forRowAtIndexPath:] for?
#Jason Coco:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
}
Just you can try with following code.
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellString = #"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellString];
if(cell == nil){
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellString];
}
cell.textLabel.text = values;
cell.textLabel.textColor = [UIColor colorWithRed:154.0/255.0 green:14.0/255.0 blue:2.0/255.0 alpha:1];
cell.textLabel.font = [UIFont systemFontOfSize:12.0];
return cell;
}
Try,
cell.textLabel.font = [UIFont systemFontOfSize:12.0];
cell.detailTextLabel.font = [UIFont systemFontOfSize:10.0];
willDisplayCell:forRowAtIndexPath: can be used for modifying the cell's background color, content view, etc, except the backgroundColor property of textlabel and detailtextlabel
Its always a good practice to do these modifications in the above method
very simple, `
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
cell.textLabel.textColor = [UIColor grayColor]; //redColor greenColor etc.
}