TableView not displaying any data except the empty rows - ios

I have following code :
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *tableId = #"details";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableId];
if(cell == nil)
{
cell = [ [UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableId];
}
[((UIImageView *)[cell viewWithTag:101]) setImage:[UIImage imageNamed:[homeInvCaptureViewModel.productArray objectAtIndex:indexPath.row]]];
return cell;
}
I have a table view in storyboard. Yet, my data is not shown up in my table rows. (i.e., imageview).

I just try your code, and it's working for me, so I see some explanations for your bug:
Did you set 101 for your ImageView's tag in your storyboard?
Did you set details as cell's identifier is in your storyboard?
Are you sure your image's name from your productArray exists in your project's images?
You should set an image at your ImageView in your storyboard to identify,

Related

Cannot set text in textview in my custom tableView cell

I am trying to load my UITextView on UItableViewCell with data but unable to set text. UITextViewDelegate is also set and attached to view controller. The text string is not empty as I checked it using debugger.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CommentCellIdentifier];
//CommentCell is my custom cell with textView.
CommentCell *commentsCell = (CommentCell*)[tableView dequeueReusableCellWithIdentifier:CommentCellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CommentCellIdentifier];
}
//Setting the images for all buttons in service row.
[commentsCell.deletecomment setImage:deleteComment forState:UIControlStateNormal];
[commentsCell.editcomment setImage:editComment forState:UIControlStateNormal];
commentsCell.deletecomment.layer.borderColor = [UIColor blackColor].CGColor;
commentsCell.editcomment.layer.borderColor = [UIColor blackColor].CGColor;
NSInteger commentIndex = 2;
//CommentsArray is NSArray with data.
[commentCell.comments setText:[NSString stringWithFormat:#"%#",[[commentsArray objectAtIndex:indexPath.row] objectAtIndex:commentIndex]]];
return cell;
}
Try changing this line:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CommentCellIdentifier];
to this line:
CommentCell *cell = (CommentCell*)[tableView dequeueReusableCellWithIdentifier:CommentCellIdentifier];
I was using wrong cellname. Just replaced "commentCell" with "commentsCell" and everything starts working.
[commentsCell.comments setText:[NSString stringWithFormat:#"%#",[[commentsArray objectAtIndex:indexPath.row] objectAtIndex:commentIndex]]];`enter code here`
If you do not need scrolling the textview DISABLE SCROLLING in order for the text to appear.
I am not sure if this is caused by the fact that both the tableview and textview are descendants of UIScrollView, but it could be.
It helped me when I was experiencing the same issue

UITableview duplicate Images by scrolling

I have the following behavior: i have a table with number of rows = 20
i have created in Storyboard UITableView Cell with UIImage.
I use the function didSelectRowAtIndexPath for show and hide a image. If i select a row the UIImage xxx.png will be displayed. If i select the same row again then the Image is hidden. That works perfekt but when i scroll down i see rows with images and i have no selected this rows.
I will only see the image when i select a row and not duplicates wehen i scroll the table.
Here is my code:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
WorkoutTableVCell *cell = [tableView dequeueReusableCellWithIdentifier:#"WorkoutCell" forIndexPath:indexPath];
cell.checkImage= nil;
if (cell == nil)
{
cell = [[WorkoutTableVCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"WorkoutCell"];
}
else{
//Old cell...get previously createdd imageview
cell.checkImage = (UIImageView*)[cell.contentView viewWithTag:1001];
}
long row = [indexPath row];
cell.lblCell.text = _MyValues[row];
return cell;
}
I hope you can understand my problem and sorry for my bad english :(
Cells are reused, so you need set the image of the cell each time. You need to have another data source that contains images for each indexPath and use that to set the image for the UIImageView in the cell.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
WorkoutTableVCell *cell = [tableView dequeueReusableCellWithIdentifier:#"WorkoutCell" forIndexPath:indexPath];
if (cell == nil)
{
cell = [[WorkoutTableVCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"WorkoutCell"];
}
long row = [indexPath row];
cell.lblCell.text = _MyValues[row];
// set the image for the UIImageView here
cell.imageView.image = _MyImages[row];
return cell;
}
An even better approach would be to have your data source be a key/value pair (like a NSDictionary) with the Keys being the text that goes in the label and the value being the image that should be assigned to the UIImageView.

UILabel with viewWithTag - (text not appearing)

have a UITableViewCell, to which I add a label on it with tag 1000.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"ChecklistItem"];
UILabel *label = (UILabel *) [cell viewWithTag:1000];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
then
UILabel *labelName = (UILabel *)[cell viewWithTag:1000]
labelName.text = #"test".
When I run, the cell is empty. Any advice?
The problem could also be that you aren't using a unique tag number. Meaning that something in your view controller scene could possibly have the same tag number that you have defined on another object.
For example, for me, I had a UITableViewCell which had a tag # of 0 and a UILabel with a tag # of 0 and another UILabel with a tag # of 1. This caused problems and made it to where tag #1 wouldn't display at all. I could see the text when I clicked on the row -- but the data wouldn't show when the row wasn't clicked on.
When I changed the tag numbers of both UILabels, it fixed the issue.
You should check if [tableView dequeueReusableCellWithIdentifier:#"ChecklistItem"] and [cell viewWithTag:5000] are returning something other than nil.
If they are, be sure to do it in this order:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//Try to reuse the cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"ChecklistItem"];
//If you can't reuse, instantiate the cell
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"ChecklistItem"];
}
//Now that you have your cell, find the label
UILabel *labelName = (UILabel *)[cell viewWithTag:5000];
//Check if the label exists just in case
if (labelName) {
//And set the text
[labelName setText:#"test"];
}
}
The issue already solved, my application was working very fine on iPhone, so I decide to make it universal. I copy all view controller to iPad storyboard. And I start doing some change on iPad storyboard.
Whatever I add/delete on iPad storyboard, didn't make any change as the main interface was iphone and the reason was that I didn't change the main interface for iPad, so while running on iPad, I was using the storyboard of iPhone.

UITableView disappearing content

As soon as the table view gets touched the cell titles (and on-tap actions) disappear. I only use standard table view cells and store the values in an array. After the values disappear the table stays scrollable. Any ideas?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
cell.textLabel.text = [[systeme objectAtIndex:indexPath.row] description];
cell.backgroundColor = [UIColor clearColor];
[cell.textLabel setTextColor:[UIColor whiteColor]];
[cell.textLabel setTextAlignment:NSTextAlignmentCenter];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[[NSNotificationCenter defaultCenter] postNotificationName:#"choseSystem" object:[systeme objectAtIndex:indexPath.row]];
}
You should be sure that the reuse identifier is the same for all cells if you use only one type of cells. You should do something similar to the following in the portion of your code where to retrieve a reusable cell:
NSString *CellIdentifier = [NSString stringWithFormat:#"CellReuseIdentifier", (long)indexPath.section];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
And make you you set the #"CellReuseIdentifier" in your xib file or your storyboard.
If you would like to use multiple custom cells for a table view you should do something similar to what you're doing, but take into account that reuse identifiers need to be configured for every type of cells.
Hope this helps!
The table view was fine. I just added its view as a subview to another view without keeping reference to the actual UITableViewController. That was the problem.

Adding subview to UITable

I'm trying to add as subview into a section in UITableView, It looks like the code is correct, the it doesn't show anything, just blank section. Here's the code that I use:
- (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];
}
if(indexPath.section==0){
cell.textLabel.text =#"<>";
}else if(indexPath.section==1){
if(indexPath.row==1){
cell.frame =CGRectMake(0,0, 100, 100);
[cell.contentView addSubview:page.view];
}
} else if(indexPath.section==2){
}
// Configure the cell.
return cell;
}
Thanx in advance..
One of the problems is that you are trying to change the height of the cell. If you want to do so, in addition to changing its frame, you must also implement tableView:heightForRowAtIndexPath: and return appropriate values for each row. If page is properly loaded (assuming it's a view controller), you can add the view as a subview. Make sure its frame falls within the bounds of the cell.
Attaching the view
Since dPage is a view controller, you will have to declare page as an ivar of class dPage and then do this in viewDidAppear:,
page = [[dPage alloc] initWithNibName:"page" bundle:nil];
and tableView:cellForRowAtIndexPath: remains unchanged.

Resources