I have a problem while scrolling images on tableview.
I am getting a Signal "0" error.
I think it is due to some memory issues but I am not able to find out the exact error.
The code is as follows,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [travelSummeryPhotosTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
}
//Photo ImageView
UIImageView *photoTag = [[UIImageView alloc] initWithFrame:CGRectMake(5.0, 5.0, 85.0, 85.0)];
NSString *rowPath =[[imagePathsDictionary valueForKey:[summaryTableViewDataArray objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
photoTag.image = [UIImage imageWithContentsOfFile:rowPath];
[cell.contentView addSubview:photoTag];
[photoTag release];
// Image Caption
UILabel *labelImageCaption = [[UILabel alloc] initWithFrame:CGRectMake(110.0, 15.0, 190.0, 50.0)];
labelImageCaption.textAlignment = UITextAlignmentLeft;
NSString *imageCaptionText =[ [imageCaptionsDictionary valueForKey:[summaryTableViewDataArray objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
labelImageCaption.text = imageCaptionText;
[cell.contentView addSubview:labelImageCaption];
[labelImageCaption release];
return cell;
}
Thanks in advance.
Signal "0" error usually means that application crashed because of low memory.
It seems that your problem is the following - you create cell subviews and add them to your cell each time cellForRowAtIndexPath method gets called - so all your allocated UI elements hang in memory and application gets out of it eventually.
To solve your problem you must create cell's subviews only once - when creating it and later just setup their contents:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [travelSummeryPhotosTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
UIImageView *photoTag = [[UIImageView alloc] initWithFrame:CGRectMake(5.0, 5.0, 85.0, 85.0)];
photoTag.tag = 10;
[cell.contentView addSubview:photoTag];
[photoTag release];
UILabel *labelImageCaption = [[UILabel alloc] initWithFrame:CGRectMake(110.0, 15.0, 190.0, 50.0)];
labelImageCaption.tag = 11;
labelImageCaption.textAlignment = UITextAlignmentLeft;
[cell.contentView addSubview:labelImageCaption];
[labelImageCaption release];
}
//Photo ImageView
NSString *rowPath =[[imagePathsDictionary valueForKey:[summaryTableViewDataArray objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
UIImageView* photoTag = (UIImageView*)[cell.contentView viewWithTag:10];
photoTag.image = [UIImage imageWithContentsOfFile:rowPath];
// Image Caption
UILabel *labelImageCaption = (UILabel*)[cell.contentView viewWithTag:11];
NSString *imageCaptionText =[ [imageCaptionsDictionary valueForKey:[summaryTableViewDataArray objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row];
labelImageCaption.text = imageCaptionText;
return cell;
}
Related
I have a grouped style Tableview which have uilabels in Tableviewcell. Now i want to set height of uilabels equal to height of cell how can i do ths???
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// here i want to make height of label equal to height of cell
UILabel *category = [[UILabel alloc] initWithFrame:CGRectMake(95,1,140,25)];
category.font = [UIFont fontWithName:#"Arial" size:14.0f] ;
category.textAlignment = NSTextAlignmentRight;
[category setBackgroundColor:[UIColor clearColor]];
[cell addSubview:category];
}
In the cellForRowAtIndexPath add; this will return current height set for your tableview:
CGFloat currentCellHeight = [self tableView:tableView heightForRowAtIndexPath:indexPath];
UILabel myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, customWidth, currentCellHeight)];
Get default cell height
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"Cell"];
UILabel *category = [[UILabel alloc]
initWithFrame:CGRectMake(0,0,cell.frame.size.width,cell.frame.size.width)];
If you want your cell's height, just do the following:
category.frame = CGRectMake(0,0,width,cell.bounds.size.height);
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Look at this
UILabel *category = [[UILabel alloc]
initWithFrame:CGRectMake(0,0,cell.bounds.size.width,cell.bounds.size.height)];
category.font = [UIFont fontWithName:#"Arial" size:14.0f] ;
category.textAlignment = NSTextAlignmentRight;
[category setBackgroundColor:[UIColor clearColor]];
[cell addSubview:category];
}
use this code...
YOu can use following to find height in
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGSize textSize = [[NSString stringWithFormat:#"%# %#",label.text] sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(200, 1000.0f) lineBreakMode:NSLineBreakByCharWrapping];
return textSize.height; //height for cell
}
I think there's two things you can do; first try reading this link from apple and review your approach. If you only need a label, why not use the cells textLabel and customize its appearance?
If you really want to use the label approach then consider adding it to the contentView instead of the cell. You can also try to get the bounds of this property, instead of the c
UILabel *category = [[UILabel alloc] initWithFrame:CGRectMake(0,0,width,cell.contentView.bounds.size.height)];
[cell.contentView addSubview:category];
Hope this helps.
// try this code
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(95,1,140,cell.frame.size.height)];
just set the cell bounds to label's frame,like below.
UILabel *myLabel = [[UILabel alloc] initWithFrame:cell.bounds];
For those that are familiar with FPPopOver: https://github.com/50pixels/FPPopover
Can the cells display subtitle? I had to attach my UITableViewController to a nib.
In the Storyboard I have the cell set up to show subtitle, however, when the popOver appears on the iPhone, only cell.textLabel.text is visible - cell.detailTextLabel.text is not appearing.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell==nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSString *entityName= [[managedObject entity]name];
cell.textLabel.text = [NSString stringWithFormat:#"%# %i", entityName, [indexPath row]];
cell.detailTextLabel.text = #"Subtitle";
}
Here is the image:
Update
After using Labels to display the subtitle, after scrolling the cell back into the view, the following happens:
if it's not working at all then alternative of that is you can use lable and set frame of lable as detail text has and add that lable as cell.contentview addsubview so this way you'll get your detail text on your tableview cell.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = (UITableViewCell*)[tblUser dequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
}
NSMutableDictionary *objUser = [arrUser objectAtIndex:indexPath.row];
strName = [objUser objectForKey:#"Name"];
strDate = [objUser objectForKey:#"Date"];
UILabel *lblName = [[UILabel alloc] initWithFrame:CGRectMake(85, 10, 215, 20)];
lblName.text = strName;
lblName.textColor = [UIColor whiteColor];
[lblName setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:lblName];
UILabel *lblDate = [[UILabel alloc] initWithFrame:CGRectMake(85, 34, 215, 20)];
lblDate.text = strDate;
lblDate.textColor = [UIColor whiteColor];
[lblDate setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:lblDate];
return cell;
}
I am having more than a table view in a view controller, it is giving error. I have no idea what is where going wrong can anyone guide. Data is not showing in table view but array has data when printed in console, i tried without array also providng static data to cell.textLabel.text, but not showing in tableview, numbers of rows checked no issue there. control does not go to cell.textLabel.text, i am not getting what is wrong. Please guide for the above. Below is the code:
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell;
if(tableView == self.mLocationTable)
{
cell = [self.mLocationTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
else{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// if([self.mLocShowArr count]!= 0)
// {
// NSString *str = [self.mLocShowArr objectAtIndex:indexPath.row];
cell.textLabel.text = #"locations";
// NSLog(#"show loc:%#", [self.mLocShowArr objectAtIndex:0]);
// }
}
if(tableView == self.mNotifyTable)
{
cell = [self.mNotifyTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UIImage *yourImage = [UIImage imageNamed:#"emma-watson-02.jpg"];
UIImageView *imageViewToPutInCell = [[UIImageView alloc] initWithImage:yourImage];
imageViewToPutInCell.frame = CGRectMake(5, 8, 55, 55);
UILabel *cellTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(68, 10, 200, 40)];
cellTextLabel.text = #"notification view";
[cell addSubview:imageViewToPutInCell];
[cell addSubview:cellTextLabel];
}
}
This is the complete error : Error [IRForTarget]: Call to a symbol-only function 'objc_msgSend' that is not present in the target.
Things to check.
Data source methods all required implemented
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
log the return value and make sure it is not 0
Give the different cell identifier for different tables
Make sure table data source and delegates are connected in the nib
Error Explanation here
Try this code !!! In your code you missed "return cell;"
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.accessoryType = UITableViewCellAccessoryNone;
}
if(tableView == self.mNotifyTable) {
cell.textLabel.text = #"locations";
UIImage *yourImage = [UIImage imageNamed:#"emma-watson-02.jpg"];
UIImageView *imageViewToPutInCell = [[UIImageView alloc] initWithImage:yourImage];
imageViewToPutInCell.frame = CGRectMake(5, 8, 55, 55);
UILabel *cellTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(68, 10, 200, 40)];
cellTextLabel.text = #"notification view";
[cell addSubview:imageViewToPutInCell];
[cell addSubview:cellTextLabel];
}
return cell;
}
Hope this solves your problem !!!
Accept the answer if it helps you !!!
I am using a table view(list view) there i am displaying images in cells,Images are displaying but not of same size its all of different size.I want all the images of same height and width.
Can any one give me the code for that.
Tnx..
Do like this,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell=nil;
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
CGRect imageFrame = CGRectMake(2, 8, 40, 40);
UIImage *img = [[[UIImage alloc] initWithData:data] autorelease];
UIImageView *customImage = [[[UIImageView alloc] initWithFrame:imageFrame] autorelease];
customImage.image=img;
[cell.contentView addSubview:customImage];
}
return cell;
}
just add image with frame in cellForRowAtIndexPath: method like bellow..
you can also use UIImageView instead of AsynchImageView
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"ImageCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithFrame:CGRectZero reuseIdentifier:CellIdentifier]
autorelease];
} else {
AsyncImageView* oldImage = (AsyncImageView*)
[cell.contentView viewWithTag:999];
[oldImage removeFromSuperview];
}
CGRect frame;
frame.size.width=75; frame.size.height=75;
frame.origin.x=0; frame.origin.y=0;
AsyncImageView* asyncImage = [[[AsyncImageView alloc]
initWithFrame:frame] autorelease];
asyncImage.tag = 999;
NSURL* url = [imageDownload
thumbnailURLAtIndex:indexPath.row];
[asyncImage loadImageFromURL:url];
[cell.contentView addSubview:asyncImage];
return cell;
}
also See This Demo for your requirement
i hope this help you...
In tableview datasource method -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath provide frame for image view
cell.imageView.frame
I am having a problem setting a UIImageView or UIView on the cell of the Grouped table on the iPhone.
For this I am using this code
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
NSArray *listData =[self.tableContents objectForKey:[self.sotreKeys objectAtIndex:[indexPath section]]];
UITableViewCell * cell = [tableView
dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier] autorelease];
}
if(indexPath.section == 1 && indexPath.row ==1)
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(240, 14, 40, 40)];
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:#"Back.png",nil]];
[cell.contentView addSubview:imageView];
[imageView release];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
return cell;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
But it is not placed on the cell . When ever I select the row it will display for that time only, what is the problem?
Does anyone have any idea what the problem is. I think the image is getting overwritten by the cell .
Thanks in advance
try making
cell.accessoryType = UITableViewCellAccessoryNone;
It seems that you are adding image on accessory view.
If yes, you can add cell.accessoryView = imageView;
I do have some ideas of what might be happening.
You are adding an image view to the contentView then you are setting the text of the textLabel which is a part of the contentView and is probably sitting on top of the image. Try this and see if you can at least see your image on the left side.
cell.imageView.image = [UIImage imageNamed:#"Back.png"];
Now when you dequeue cells you need to remember that all the views you added last time you created the cell are still there, so as you scroll you will just be stacking back buttons on top of each other.
Also the following line [tableView deselectRowAtIndexPath:indexPath animated:YES]; is dead code because it occurs after a return statement. You might want to place that in the delegate call – tableView:willDisplayCell:forRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
NSArray *listData =[self.tableContents objectForKey:[self.sotreKeys objectAtIndex:[indexPath section]]];
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if(cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:SimpleTableIdentifier] autorelease];
}
if(indexPath.section == 1 && indexPath.row ==1)
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(240, 14, 40, 40)];
imageView.image = [UIImage imageNamed:#"Back.png"];
[cell.contentView addSubview:imageView];
[imageView release];
}
cell.textLabel.text = [listData objectAtIndex:indexPath.row];
return cell;
}
Make sure that your image is named "Back.png" not "back.png" because the iOS on the phone is key sensitive.