How are you all. I'm having a weird issue with my tableviewcell. When I runn this on Simulator. It shows proper layout as in image 1.
but when I run this on device. It has colored lines in it on all tableviews of app, like image 2.
Is this something with iOS 7? I've cleared background color of cell in tablview:willDisplayCell:.
Code is
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
BarsCustomCell *cell= [BarsCustomCell resuableCellForTableView:tableView withOwner:self];
Bars *currentValue= [self.data objectAtIndex:indexPath.row];
if(indexPath.row==(self.data.count-1)){
[cell updateWithBars:currentValue isLast:YES isFirst:NO] ;
}else if (indexPath.row==0){
[cell updateWithBars:currentValue isLast:NO isFirst:YES] ;
}else{
[cell updateWithBars:currentValue isLast:NO isFirst:NO] ;
}
}
and Tableviewcell sublcassm method for updating.
-(void) updateWithBars:(Bars *)bars isLast:(BOOL)isLast isFirst:(BOOL)isFirst{
self.nameLbl.text= bars.name;
self.addressLbl.text= bars.vicinity;
double distance = [[[LOTVLocationManager sharedManager] mockedLocation] distanceFromLocation:bars.location];
self.distanceLbl.text= [NSString stringWithFormat:#"%.2f km",distance/1000];
if(isFirst){
self.bgImageview.image= [UIImage imageNamed:#"sport_top_bg.png"];
self.nameLbl.center= CGPointMake(self.nameLbl.center.x, self.nameLbl.center.y+3);
}
else if(isLast){
self.bgImageview.image= [UIImage imageNamed:#"sport_bottom_bg.png"];
self.addressLbl.center= CGPointMake(self.addressLbl.center.x, self.addressLbl.center.y-3);
}
}
Resolved the issue. It was due to TableviewCell's background color. Some iOS Versions support cell.backgroundColor and some support only cell.contentView.backgroundColor. I wrote both for cell and contentView to fix the issue.
Related
I have an ordinary tableview with custom cells, working perfectly on iOS 6.0 but after upgrading the app to iOS 10, scattered problem arises.
Note: The app works as expected on iPhone 5, both on simulator and on a real device. All devices are running iOS 10.2 but iPhone 6 and above has the issues described below.
Some tableviews work fine just like before, while one of the tableViews always shows exactly 1 cell (even tough cellForRowAtIndexPath is called 7 times) and another table shows no cells at all despite cellForRowAtIndexPath getting called twice.
I am wondering why the method is called if the tableview does not care to display the result?
I am at a total loss as to what is going on and how to fix it. Been at it for a day with no progress at all. I have tried cleaning and running different builds and can not get the affected tableviews to behave correctly. I don't know what to try next? Any help is appreciated, thanks!
Ok since you need some code here is a part of it that is not that sensitive. DataSource:
- (void)viewDidLoad
{
[super viewDidLoad];
NOSUserInfo2 *userInfo = [S24SharedUserHandler currentUser];
dataSource = [NSMutableArray arrayWithArray:[userInfo children]];
if([userInfo student] || [userInfo teacher])
{
[dataSource insertObject:userInfo atIndex:0];
}
self.contentSizeForViewInPopover = CGSizeMake(250, 45*dataSource.count-1);
self.tableView.backgroundColor=[UIColor colorWithWhite:0.95f alpha:1];
self.tableView.scrollEnabled=NO;
[self.tableView registerNib:[UINib nibWithNibName:#"NOSPersonSelectorCell" bundle:nil] forCellReuseIdentifier:#"PersonPopoverCell"];
}
This gets called 2 times:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"PersonPopoverCell";
NOSPersonSelectorCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
cell.textLabel.font = [UIFont fontWithName:#"HelveticaNeue-Medium" size:15];
cell.textLabel.backgroundColor=[UIColor clearColor];
NSObject *dataObject = [dataSource objectAtIndex:[indexPath row]];
if ([dataObject isKindOfClass:[NOSUserInfo2 class]]) {
cell.textLabel.text = [(NOSUserInfo2 *)dataObject name];
cell.pk = [(NOSUserInfo2 *)dataObject personPK];
}
else {
cell.textLabel.text = [(NOSChild2 *)dataObject childName];
cell.pk = [(NOSChild2 *)dataObject childPK];
}
cell.textLabel.textColor = [UIColor colorWithWhite:0.18f alpha:1];
//NSLog(#"%d", [S24SharedUserHandler selectedPk]);
cell.checkmark.hidden=cell.pk!=[S24SharedUserHandler selectedPk];
return cell;
}
And the result is that the tableview is empty.
New information 11 Jan 2017
The app works when testing on phone, but not on simulator. I still have no idea what is wrong and am really dissapointed in the downvotes I am still getting for asking this question. I would appreciate if somebody can explain why they think it is a bad question.
Apparently everything works on an iPhone 5. It does not work on iPhone 6 and up. Be advised that the iOS is still 10.2, for both the iPhone 5 and iPhone 6 and 7 also have iOS 10.2
Since the only difference between working and not working is the device, not ios version, I am now leaning towards it being an UI bug that only occurs at certain sizes.
One other issue that arises is that my gesturerecognizer also only works on iPhone5 and not 6+
New info!
I can fix the problem by commenting the heightForRowAtIndexPath code. This now means that I need some other way to adjust the height of certain cells and that is the current problem. I still have no idea at all why uitableview behaves this way.
The reason for this particular problem was that the method "heightForRowAtIndexPath" returns a double on iPhone 5 and long on iPhone 6, to be correct, one should use a defined datatype called "CGFloat"!
It was not easy to find this problem and I hope I can help someone else with this. Also thanks to anyone that tried to help!
Images constrain's :
Image is set to scale-fill.
I am using SDWebImage Library to load images from server..
When image is loaded it over lap's the text area which is exactly below my image.
Here are the screen shot's of main layout.. No issues from constrain's found.
Here is the image when it load's look like:
Here is the code:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
cell=[tableView dequeueReusableCellWithIdentifier:#"fiscocustomcell"];
int i = (int) indexPath.row;
Newsletter * newstemp = [newsposts objectAtIndex:i];
//get a dispatch queue
;
cell.Title.text=[newstemp title];
cell.Title.numberOfLines=0;
[cell.Title sizeToFit];
cell.Postedby.text=#"Posted by";
cell.Postedby.numberOfLines =0;
[cell.Postedby sizeToFit];
cell.NewsDesc.text=[newstemp desc];
cell.NewsDesc.numberOfLines=0;
[cell.NewsDesc sizeToFit];
NSURL *urlimage = [NSURL URLWithString:[newstemp imagelink]];
[cell.imageView sd_setImageWithURL:urlimage placeholderImage:[UIImage imageNamed:#"service-1.png"]];
[cell setNeedsDisplay];
[cell layoutIfNeeded];
return cell;
}
I am stucked from last 1 week with this issues used auto resolve constrain's etc as well nothing works.
It should be like this:
Solved Problem
The issue is cell.imageView, I am using custom cell so it must be custom uiimage naned there like:
[cell.mycustomimage sd_setImageWithURL:urlimage placeholderImage:[UIImage imageNamed:#"service-1.png"]];
cell.imageView alway's place the image on the right of cell.
Thanks every one hope that bug will never happen's to any one again ever...
I have to create something similar to above mentioned image. I have a view and i need border after eat view like {breakfast, brunch,etc..}
for giving border I was have following code.
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(0.0f, 43.0f, menuHeadView.frame.size.width, 1.0f);
bottomBorder.backgroundColor = [UIColor colorWithWhite:0.8f
alpha:1.0f].CGColor;
[menuHeadView.layer addSublayer:bottomBorder];
it works fine for single view but if I have an array for those views and I want to have border after each view using indexPath it doesn't work since it doesn't allow
[array objectAtIndex:i].layer;
help please! Thanks in advance.
If you have array of views you probably should cast:
Change :
[array objectAtIndex:i].layer;
To:
((UIView*)[array objectAtIndex:i]).layer;
EDIT:
Based on #Mischa comment:
Casting is telling the array what object is in it. If you have different kind of objects in array (you really shouldn't!) or to be super safe you can change casting to assign:
id myUnknownObject = [array objectAtIndex:i];
if([myUnknownObject isKindOfClass:[UIView class]]) {
((UIView*)myUnknownObject).layer...
} else {
NSLog(#"%#",[myUnknownObject class]);
}
But base on your comment you contain NSStrings in your array so you can't add layer to this objects. Please check your console, it's probably NSString.
Of course since you mentioned indexPath, and if you're using TableView with rows. You should use the good stuff from reusability and it method:
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
NSDictionary *cellDic = [self.heartbeats objectAtIndex:indexPath.row];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
//here goes reusability part like styling and stuff, this will calling only once for every reusable cell. So for example for cells height 44 this will called only 13 times for iPhone screen.
//HERE you should manipulate with layer!
}
//here goes your custom text of every cell - like "Breakfast", "Brunch" and so on. This will calls for every row which is about to show up.
//HERE you should manipulate with text
return cell;
}
Ive got a chat system in my app, and im attempting to make dynamic cells to have dynamic height according to how much text is in the cell, pretty common thing people try to do, however i cant get to get mine working properly.
Also the messages align to the right, the sender is supposed to be on the left and the reciever should be on the right... heres what i have done with the storyboard.
created a TableView with 2 dynamic prototypes, inside a UIViewControllerhere is the viewController for that... each cell has a label, one left one right, the whole right and left thing work... heres my issue. Its only pulling to the right for all, so basically my if isnt happening and my else is overruling. Heres a SS.
So i have two issues... Text wont have multiple lines... along with wont do dynamic height, also... if someone can point me i the right dirrection for getting sender and reciever to show on different sides.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *myWords = [[getMessage objectAtIndex:indexPath.row] componentsSeparatedByString:#":oyr4:"];
if (myWords[1] == [MyClass str]){
static NSString *sender = #"sender";
UITableViewCell* cellSender = [_tableView dequeueReusableCellWithIdentifier:sender];
messageContentTo = (UILabel *)[cellSender viewWithTag:83];
self->messageContentTo.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.8];
self->messageContentTo.lineBreakMode = NSLineBreakByWordWrapping;
[self->messageContentTo sizeToFit];
messageContentTo.text = myWords[4];
return cellSender;
} else {
static NSString *reciever = #"reciever";
UITableViewCell* cellReciever = [_tableView dequeueReusableCellWithIdentifier:reciever];
messageContentFrom = (UILabel *)[cellReciever viewWithTag:84];
messageContentFrom.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.8];
messageContentFrom.lineBreakMode = NSLineBreakByWordWrapping;
messageContentFrom.font = [UIFont systemFontOfSize:22];
messageContentFrom.numberOfLines = 0;
messageContentFrom.text = myWords[4];
return cellReciever;
}
}
#pragma mark - UITableViewDelegate methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGSize size = [[getMessage objectAtIndex:indexPath.row]
sizeWithFont:[UIFont systemFontOfSize:22]
constrainedToSize:CGSizeMake(1000, CGFLOAT_MAX)];
return size.height + 15;
}
The left-right problem might be due to this:
if (myWords[1] == [MyClass str])
If myWords[1] is a string, you need to use isEqualToString: not "==" to compare it.
if ([myWords[1] isEqualToString:[MyClass str]])
As far as the label height not adjusting properly, it's hard to tell what's going on without knowing how your labels are set up. I usually do it by making constraints between the label and the top and bottom of the cell in IB. That way, when you change the height of the cell, the label will follow (and of course, set numberOfLines to 0). Also, in your sizeWithFont:constrainedToSize: method, the width you pass into CGSizeMake() should be the width of the label, not 1000.
I'm trying to figure out what might be happening in the following code segment. I have a collection view and I'm showing saved images as thumbnails. I'm also inserting a stock "New Image" icon at the end so the user can add an additional image.
On the iPad simulator it appears fine but when I run on the device I do not see the "New Image" icon. I can touch it to open up the camera view controller for capture/selection but the image does not display. Any ideas? Here's the code...
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *cellIdentifier = #"cvCell";
CVCell *cell = (CVCell *)[[self sectionImagesCollectionView] dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
if ([indexPath row] < [sectionImages count]){
// Have an image so assign the photograph
RFHSectionImages *sectionImage = [sectionImages objectAtIndex:[indexPath row]];
UIImage *image = [UIImage imageWithData:[sectionImage photograph]];
[[cell imageView] setImage:image];
} else {
// Use the standard image
UIImage *newPhoto = [UIImage imageNamed:#"New Image.png"];
[[cell imageView] setImage:newPhoto];
}
return cell;
}
Here's a small detail that many developers have wasted hours upon:
Case Sensitivity
Really, it all boils down to:
iPhone Simulator: Case-Insensitive
iOS device: Case-Sensitive
So, you might have 'New Image.png' in your code, but the actual image name is 'new image.png'. It might even be something like 'nEw iMaGe.png'.
This will work fine on the simulator, but not on the device - the device simply won't find the image.
This has happened to me for everything from images to plists.
Check your Cases!
I had a similar problem, but the culprit was network latency — had to manually call self.collectionView.reloadData() to get things showing up. Locally, the data apparently loaded quickly enough that this wasn’t an issue.