I have the following code that render scroll view inside table view with three pages, I want the pages to be changed each 5 seconds , how can I do that ?
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier: sliderIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sliderIdentifier];
}
if (sliderItems != nil && sliderItems.count > 0) {
UIScrollView *scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,self.view.frame.size.width, 200)];
scroll.scrollEnabled = YES;
for (int i = 0; i < sliderItems.count ; i++) {
CGFloat xOrigin = i * self.view.frame.size.width;
UIImageView *awesomeView = [[UIImageView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, 200)];
ItemResponse *test = [ItemResponse new];
test = sliderItems[i];
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//this will start the image loading in bg
dispatch_async(concurrentQueue, ^{
NSString *urlStr = test.listingImage;
NSURL *imageUrl = [NSURL URLWithString:urlStr];
NSData *imageData = [NSData dataWithContentsOfURL:imageUrl];
//this will set the image when loading is finished
dispatch_async(dispatch_get_main_queue(), ^{
awesomeView.image = [UIImage imageWithData:imageData];
[scroll addSubview:awesomeView];
UILabel *iconAdLabel = [[UILabel alloc]init];
iconAdLabel.frame = CGRectMake(0 + (i * self.view.frame.size.width),130,self.view.frame.size.width,70);
iconAdLabel.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
NSString *titleStr = [NSString stringWithFormat:#" %# ", test.listingTitle];
iconAdLabel.text = titleStr;
UIColor *color = [self getUIColorObjectFromHexString:#"#000000" alpha:0.6];
iconAdLabel.backgroundColor = color;
UIColor *textcolor = [self getUIColorObjectFromHexString:#"#ffffff" alpha:1.0];
iconAdLabel.textColor = textcolor;
iconAdLabel.textAlignment = NSTextAlignmentRight;
UIFont *font=[UIFont fontWithName:#"NotoKufiArabic" size:14.0f];
iconAdLabel.font = font;
iconAdLabel.numberOfLines = 2;
[scroll addSubview:iconAdLabel];
});
});
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * sliderItems.count , 200);
dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//this will start the image loading in bg
dispatch_async(concurrentQueue, ^{
dispatch_async(dispatch_get_main_queue(), ^{
[self.view addSubview:scroll];
});
});
}
return cell;
You can use a NSTimer object
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:#selector(timerAction) userInfo:nil repeats:YES];
with action
-(void)timerAction
{
[scroll scrollRectToVisible:CGRectMake(x, y, width, height) animated:YES];
}
Also you need to invalidate the timer Object when the ViewController Disappears. So if you have multiple cells , use an NSArray to keep track of the timer objects and invalidate when no longer needed [timer invalidate]
Related
I have four images on a viewcontroller.On the click of those images a newViewController i.e. LargeImageViewController opens. On the LargeImageViewController there is ScrollView which does horizontal scrolling. On click of every button the images on LargeImageViewController starts from image1 ,then shows image2,then image 3,then image 4.
I want that if image 2 is clicked then the images on LargeImageViewController should start image2,then image 3,then image 4.....but when it goes to previous image then it should show image 4,image3,image 2 and image1 also.
How this can be achieved??
Code that I am using are as follows:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// int pageCount=4;
NSArray *imgArray = [self.tripDetails valueForKey:#"Flightimageurl"];
width = [UIScreen mainScreen].bounds.size.width;
height = [UIScreen mainScreen].bounds.size.height;
_scroller = [[UIScrollView alloc]initWithFrame:
CGRectMake(0,64,width,height)];
_scroller.contentSize=CGSizeMake([imgArray count]*_scroller.bounds.size.width,_scroller.bounds.size.height);
CGRect ViewSize=_scroller.bounds;
for(int i=0;i<[imgArray count];i++)
{
UIImageView *imgView1=[[UIImageView alloc]initWithFrame:ViewSize];
NSString *ImageURL = [imgArray objectAtIndex:i];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
imgView1.image=[UIImage imageWithData:imageData];
[_scroller addSubview:imgView1];
[self.view addSubview:_scroller];
ViewSize =CGRectOffset(ViewSize,_scroller.bounds.size.width,0);
}
}
Kindly help with suggesting the changes.
-(void)singleTapping:(UIGestureRecognizer *)recognizer {
int imageTag = (int) recognizer.view.tag;
NSDictionary *dictCurrentWish = [arrLatestScrollData objectAtIndex:pageNumberSaved];
scrollimagePostView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, kSCREEN_WIDTH, kSCREEN_HEIGHT)];
scrollimagePostView.pagingEnabled=YES;
scrollimagePostView.delegate=self;
UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
[scrollimagePostView addGestureRecognizer:gr];
NSMutableArray *arrTotalImages = [[NSMutableArray alloc]initWithCapacity:0];
[arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic1"]];
[arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic2"]];
[arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic3"]];
[arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic4"]];
int x=0;
CGRect innerScrollFrame = scrollimagePostView.bounds;
for (int i=0; i<arrTotalImages.count; i++) {
imgViewPost=[[UIImageView alloc]initWithFrame:CGRectMake(x, 60, kSCREEN_WIDTH,kSCREEN_HEIGHT-90)];
NSString *strImage =[NSString stringWithFormat:#"%#", [arrTotalImages objectAtIndex:i]];
NSString *strURL=[strImage stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
NSURL* urlAddress1 = [[NSURL alloc] initWithString:strURL];
[imgViewPost sd_setImageWithURL:urlAddress1 placeholderImage:wishPlaceHolderImage];
imgViewPost.contentMode = UIViewContentModeScaleAspectFit;
imgViewPost.tag = VIEW_FOR_ZOOM_TAG;
UIScrollView *pageScrollView = [[UIScrollView alloc]
initWithFrame:innerScrollFrame];
pageScrollView.minimumZoomScale = 1.0f;
pageScrollView.maximumZoomScale = 6.0f;
pageScrollView.zoomScale = 1.0f;
pageScrollView.contentSize = imgViewPost.bounds.size;
pageScrollView.delegate = self;
pageScrollView.showsHorizontalScrollIndicator = NO;
pageScrollView.showsVerticalScrollIndicator = NO;
[pageScrollView addSubview:imgViewPost];
[scrollimagePostView addSubview:imgViewPost];
x=x+kSCREEN_WIDTH;
if (i < 2) {
innerScrollFrame.origin.x += innerScrollFrame.size.width;
}
}
scrollimagePostView.contentSize = CGSizeMake(x, scrollimagePostView.frame.size.height );
scrollimagePostView.backgroundColor = [UIColor blackColor];
[self.view addSubview:scrollimagePostView];
[scrollimagePostView setContentOffset:CGPointMake(scrollimagePostView.frame.size.width*(imageTag-1), 0.0f) animated:NO];
btnCloseFullIMageView = [[UIButton alloc]initWithFrame:CGRectMake(kSCREEN_WIDTH-80, 25, 70, 25)];
[btnCloseFullIMageView setTitle:#"Close" forState:UIControlStateNormal];
[btnCloseFullIMageView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
btnCloseFullIMageView.backgroundColor = [UIColor blackColor];
btnCloseFullIMageView.layer.borderColor = [UIColor whiteColor].CGColor;
btnCloseFullIMageView.layer.borderWidth = 0.5;
btnCloseFullIMageView.layer.cornerRadius = 3.0;
btnCloseFullIMageView.clipsToBounds = TRUE;
[btnCloseFullIMageView addTarget:self action:#selector(closeFullImageView:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnCloseFullIMageView];
}
I have four images on a Viewcontroller A .On the click of those images Viewcontroller B having UIScrollView presents that has image view and it shows all those four imgaes....Image1 ,image 2,image 3,image 4.
I want that when image 2 is clicked then image 2 appeas as the first image on Viewcontroller B ,then image 3,then image 4...Also,when user moves left then it shows previous images including image1 too.
I have searched a lot but couldn't find solution to this problem Kindly.help
The code I have used are as follows:
- (void)viewDidLoad {
[super viewDidLoad];
width = [UIScreen mainScreen].bounds.size.width;
height = [UIScreen mainScreen].bounds.size.height;
_scroller = [[UIScrollView alloc]initWithFrame:
CGRectMake(0,64,width,height)];
_scroller.contentSize=CGSizeMake(pageCount*_scroller.bounds.size.width,_scroller.bounds.size.height);
_scroller.pagingEnabled=YES;
_scroller.showsHorizontalScrollIndicator=YES;
CGRect ViewSize=_scroller.bounds;
NSArray *imgArray = [self.tripDetails valueForKey:#"Flightimageurl"];
for(int i=0;i<[imgArray count];i++)
{
UIImageView *imgView1=[[UIImageView alloc]initWithFrame:ViewSize];
NSString *ImageURL = [imgArray objectAtIndex:i];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
imgView1.image=[UIImage imageWithData:imageData];
[_scroller addSubview:imgView1];
[self.view addSubview:_scroller];
ViewSize =CGRectOffset(ViewSize,_scroller.bounds.size.width,0);
}
}
Use This Code It will be helpful to you
-(void)singleTapping:(UIGestureRecognizer *)recognizer {
int imageTag = (int) recognizer.view.tag;
NSDictionary *dictCurrentWish = [arrLatestScrollData objectAtIndex:pageNumberSaved];
scrollimagePostView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0, kSCREEN_WIDTH, kSCREEN_HEIGHT)];
scrollimagePostView.pagingEnabled=YES;
scrollimagePostView.delegate=self;
UITapGestureRecognizer *gr = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleGesture:)];
[scrollimagePostView addGestureRecognizer:gr];
NSMutableArray *arrTotalImages = [[NSMutableArray alloc]initWithCapacity:0];
[arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic1"]];
[arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic2"]];
[arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic3"]];
[arrTotalImages addObject:[dictCurrentWish objectForKey:#"pic4"]];
int x=0;
CGRect innerScrollFrame = scrollimagePostView.bounds;
for (int i=0; i<arrTotalImages.count; i++) {
imgViewPost=[[UIImageView alloc]initWithFrame:CGRectMake(x, 60, kSCREEN_WIDTH,kSCREEN_HEIGHT-90)];
NSString *strImage =[NSString stringWithFormat:#"%#", [arrTotalImages objectAtIndex:i]];
NSString *strURL=[strImage stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
NSURL* urlAddress1 = [[NSURL alloc] initWithString:strURL];
[imgViewPost sd_setImageWithURL:urlAddress1 placeholderImage:wishPlaceHolderImage];
imgViewPost.contentMode = UIViewContentModeScaleAspectFit;
imgViewPost.tag = VIEW_FOR_ZOOM_TAG;
UIScrollView *pageScrollView = [[UIScrollView alloc]
initWithFrame:innerScrollFrame];
pageScrollView.minimumZoomScale = 1.0f;
pageScrollView.maximumZoomScale = 6.0f;
pageScrollView.zoomScale = 1.0f;
pageScrollView.contentSize = imgViewPost.bounds.size;
pageScrollView.delegate = self;
pageScrollView.showsHorizontalScrollIndicator = NO;
pageScrollView.showsVerticalScrollIndicator = NO;
[pageScrollView addSubview:imgViewPost];
[scrollimagePostView addSubview:imgViewPost];
x=x+kSCREEN_WIDTH;
if (i < 2) {
innerScrollFrame.origin.x += innerScrollFrame.size.width;
}
}
scrollimagePostView.contentSize = CGSizeMake(x, scrollimagePostView.frame.size.height );
scrollimagePostView.backgroundColor = [UIColor blackColor];
[self.view addSubview:scrollimagePostView];
[scrollimagePostView setContentOffset:CGPointMake(scrollimagePostView.frame.size.width*(imageTag-1), 0.0f) animated:NO];
btnCloseFullIMageView = [[UIButton alloc]initWithFrame:CGRectMake(kSCREEN_WIDTH-80, 25, 70, 25)];
[btnCloseFullIMageView setTitle:#"Close" forState:UIControlStateNormal];
[btnCloseFullIMageView setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
btnCloseFullIMageView.backgroundColor = [UIColor blackColor];
btnCloseFullIMageView.layer.borderColor = [UIColor whiteColor].CGColor;
btnCloseFullIMageView.layer.borderWidth = 0.5;
btnCloseFullIMageView.layer.cornerRadius = 3.0;
btnCloseFullIMageView.clipsToBounds = TRUE;
[btnCloseFullIMageView addTarget:self action:#selector(closeFullImageView:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnCloseFullIMageView];
}
I have a Method wich create an UIScrollView and your subviews programmatically. One of your views is a MoviewPlayer...While the scrollview is being created, I need to allow the user to exit the screen (before the loading ends). Then, I've called this method in another NSThread.
But I'm getting the following error:
[__NSCFData _pickableRoutesDidChangeNotification:]: unrecognized selector sent to instance
I think it's not possible to do it in another Thread. Then, How could I allow the user to exit the view before the loading ends?
Theres my code:
-(void) viewDidAppear:(BOOL)animated {
[NSThread detachNewThreadSelector:#selector(criarScrollMidias:) toTarget:self withObject:self.eventoAtual];
}
-(void) criarScrollMidias:(Evento *)evento {
NSLog(#"criar scroll midias");
NSMutableArray *listaImagens = evento.atracao.images;
NSMutableArray *listaVideos = evento.atracao.videos;
if([listaVideos count] > 0) {
self.listaVideoPlayers = [[NSMutableArray alloc]init];
}
[self.scrollImVd setPagingEnabled:YES];
if(![self.eventoAtual.atracao.imageLarge isKindOfClass:[NSNull class]])
{
UIImageView *imgViewAtracao = [[UIImageView alloc]initWithImage:self.eventoAtual.atracao.imageLarge];
[imgViewAtracao setContentMode:UIViewContentModeScaleAspectFit];
[imgViewAtracao setFrame:CGRectMake(0, 0, self.scrollImVd.frame.size.width, self.scrollImVd.frame.size.height)];
[self.scrollImVd addSubview:imgViewAtracao];
}
for (int iCnt = 0; iCnt < [listaImagens count]; iCnt++) {
NSString *imgURL = [listaImagens objectAtIndex:iCnt];
UIImage *imagemAtracao = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imgURL]]];
UIImageView *imgViewAtracao = [[UIImageView alloc]initWithImage:imagemAtracao];
[imgViewAtracao setContentMode:UIViewContentModeScaleAspectFit];
if(![self.eventoAtual.atracao.imageLarge isKindOfClass:[NSNull class]])
[imgViewAtracao setFrame:CGRectMake(0+self.scrollImVd.frame.size.width*(iCnt+1), 0, self.scrollImVd.frame.size.width, self.scrollImVd.frame.size.height)];
else
[imgViewAtracao setFrame:CGRectMake(0+self.scrollImVd.frame.size.width*iCnt, 0, self.scrollImVd.frame.size.width, self.scrollImVd.frame.size.height)];
[self.scrollImVd addSubview:imgViewAtracao];
}
for (int iCnt = 0; iCnt < [listaVideos count]; iCnt++) {
NSString *videoURLStr = [listaVideos objectAtIndex:iCnt];
NSURL *videoURL = [NSURL URLWithString:videoURLStr];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[moviePlayer setShouldAutoplay:NO];
[moviePlayer.view setBackgroundColor:[UIColor colorWithPatternImage:[self gerarPreviewVideo:videoURL]]];
CGFloat posicaoInicial = 0.0;
if(![self.eventoAtual.atracao.imageLarge isKindOfClass:[NSNull class]])
posicaoInicial = self.scrollImVd.frame.size.width * ([listaImagens count] + 1);
else
posicaoInicial = self.scrollImVd.frame.size.width * [listaImagens count];
[moviePlayer.view setFrame:CGRectMake(posicaoInicial+self.scrollImVd.frame.size.width*iCnt, 0, self.scrollImVd.frame.size.width, self.scrollImVd.frame.size.height)];
UIButton *playButton = [[UIButton alloc] initWithFrame:CGRectMake(moviePlayer.view.frame.origin.x+(self.scrollImVd.frame.size.width/2)-34, moviePlayer.view.frame.origin.y+(self.scrollImVd.frame.size.height/2)-33, 67, 66)];
[playButton setImage:[UIImage imageNamed:#"play.png"] forState:UIControlStateNormal];
playButton.tag = iCnt;
[playButton addTarget:self action:#selector(playButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.scrollImVd addSubview:moviePlayer.view];
[self.scrollImVd addSubview:playButton];
[self.listaVideoPlayers addObject:moviePlayer];
}
if(![self.eventoAtual.atracao.imageLarge isKindOfClass:[NSNull class]])
[self.scrollImVd setContentSize:CGSizeMake(self.scrollImVd.frame.size.width * ([listaImagens count] + [listaVideos count] + 1), self.scrollImVd.frame.size.height)];
else
[self.scrollImVd setContentSize:CGSizeMake(self.scrollImVd.frame.size.width * ([listaImagens count] + [listaVideos count]), self.scrollImVd.frame.size.height)];
[self.viewLoading setHidden:YES];
}
I've debugged and discovered that the problem is when I try to generate the preview in another Thread:
-(UIImage *) gerarPreviewVideo:(NSURL *)videoURL {
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
AVAssetImageGenerator *generateImg = [[AVAssetImageGenerator alloc] initWithAsset:asset];
NSError *error = NULL;
CMTime time = CMTimeMake(1, 65);
CGImageRef refImg = [generateImg copyCGImageAtTime:time actualTime:NULL error:&error];
UIImage *thumbnail= [[UIImage alloc] initWithCGImage:refImg];
return thumbnail;
}
How could I resolve it?
i can not align to the right a texview in a Custom TableViewCell.
I tried with NSTextAlignmentRight but simply doesn't work.
I adjust all the layout programmatically, maybe i forgot some checkbox to uncheck in my storyboard.
Sorry for my english, y hope you understand!
Here's my code inside cellForRowAtIndexPath:
cell = [self.tablaChat dequeueReusableCellWithIdentifier:simpleTableIdentifierUser];
if (cell == nil) {
cell = [[ChatTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifierUser];
}
cell.mensajeUsuario2.text = [NSString stringWithFormat:#"%#", [[self.dict_mensajes valueForKey:#"mensaje"] objectAtIndex:indexPath.row]];
NSString *dateAsString = [[self.dict_mensajes valueForKey:#"timestamp"] objectAtIndex:indexPath.row];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:#"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [formatter dateFromString:dateAsString];
//[self convertirFecha:date];
cell.labelUsuario2.text = [NSString stringWithFormat:#"%# el %#", [[self.dict_mensajes valueForKey:#"nombre"] objectAtIndex:indexPath.row], [self convertirFecha:date]];
cell.mensajeUsuario2.frame = CGRectMake(cell.mensajeUsuario2.frame.origin.x,
cell.mensajeUsuario2.frame.origin.y,
self.view.frame.size.width - cell.imagenUsuario2.frame.size.width - 25,
cell.mensajeUsuario2.frame.size.height);
cell.imagenUsuario2.frame = CGRectMake(self.view.frame.size.width - cell.imagenUsuario2.frame.size.width - 10,
cell.imagenUsuario2.frame.origin.y,
cell.imagenUsuario2.frame.size.width,
cell.imagenUsuario2.frame.size.height);
CGFloat fixedWidth = cell.mensajeUsuario2.frame.size.width;
CGSize newSize = [cell.mensajeUsuario2 sizeThatFits:CGSizeMake(fixedWidth, MAXFLOAT)];
CGRect newFrame = cell.mensajeUsuario2.frame;
newFrame.size = CGSizeMake(fmaxf(newSize.width, fixedWidth), newSize.height);
cell.mensajeUsuario2.frame = newFrame;
cell.mensajeUsuario2.scrollEnabled = NO;
[cell.mensajeUsuario2.layer setBorderWidth: 1.0];
[cell.mensajeUsuario2.layer setCornerRadius:8.0f];
[cell.mensajeUsuario2.layer setMasksToBounds:YES];
alturaCelda = cell.mensajeUsuario2.frame.size.height + cell.labelUsuario2.frame.size.height;
cell.mensajeUsuario2.backgroundColor = Rgb2UIColorMediumLight(0, 0, 0);
cell.mensajeUsuario2.textColor = Rgb2UIColorMask(255, 255, 255);
cell.labelUsuario2.frame = CGRectMake(cell.labelUsuario2.frame.origin.x,
alturaCelda - 10,
self.view.frame.size.width - cell.imagenUsuario2.frame.size.width - 30,
cell.labelUsuario2.frame.size.height);
NSString *urlImagen = [NSString stringWithFormat:#"%#", [[self.dict_mensajes valueForKey:#"foto"] objectAtIndex:indexPath.row]];
NSURL *imageURL = [NSURL URLWithString:urlImagen];
UIImage *image;
// 1. Check the image cache to see if the image already exists. If so, then use it. If not, then download it.
if ([[ImageCache sharedImageCache] DoesExist:urlImagen] == true)
{
image = [[ImageCache sharedImageCache] GetImage:urlImagen];
cell.imagenUsuario2.image = image;
}
else
{
dispatch_async(kBgQueue, ^{
NSData *imgData = [NSData dataWithContentsOfURL: imageURL];
if (imgData) {
UIImage *image2 = [UIImage imageWithData:imgData];
if (image2) {
dispatch_async(dispatch_get_main_queue(), ^{
ChatTableViewCell *updateCell = (id)[tableView cellForRowAtIndexPath:indexPath];
if (updateCell)
updateCell.imagenUsuario2.image = image2;
// Add the image to the cache
[[ImageCache sharedImageCache] AddImage:urlImagen :image2];
});
}
}
});
}
[cell.mensajeUsuario2 sizeToFit];
[cell.mensajeUsuario2 layoutIfNeeded];
cell.mensajeUsuario2.textAlignment = NSTextAlignmentRight;
I solved in this way:
i moved the "cell.mensajeUsuario2.frame" declaration to the bottom and i change it to this.
cell.mensajeUsuario2.frame = CGRectMake(cell.imagenUsuario2.frame.origin.x - 10 - cell.mensajeUsuario2.frame.size.width,
cell.mensajeUsuario2.frame.origin.y,
cell.mensajeUsuario2.frame.size.width,
cell.mensajeUsuario2.frame.size.height);
Just updated to iOS 8.0 this morning. I have a piece of code which created some labels and displays them on the scree next to some images. It was working fine before the update. Now the label and the image is not displaying. Can some one please help as I have tried everything I can think of and nothing has solved my issue and couldn't find anyone else with a similar issue. Code attached below.
UIView *labelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, kCategoryLabelHieght)];
labelView.backgroundColor = [self colorWithHexString:#"2D2D2D"];
UILabel *categoryTitle = [[UILabel alloc] initWithFrame:CGRectMake(40, 0, 200, kCategoryLabelHieght)];
categoryTitle.textAlignment = NSTextAlignmentLeft;
categoryTitle.text = text;
categoryTitle.font = [UIFont fontWithName:#"HelveticaNeue" size:14];
codeAppDelegate *appDelegate = (codeAppDelegate *)[[UIApplication sharedApplication] delegate];
NSArray *fetchedCategory = [appDelegate getCategoryByName:text];
UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(10, 2, 20, 20)];
if(fetchedCategory.count)
{
for (int t=0; t<fetchedCategory.count; t++) {
Dealcategory_List *catList = [fetchedCategory objectAtIndex:t];
NSString *titleImage = [self URLEncodeString:[NSString stringWithFormat:#"%#",catList.image]];
NSURL *url = [NSURL URLWithString:titleImage];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *imgTabs = [UIImage imageWithData:data];
// [header2 setImage:imgTabs forState:UIControlStateNormal];
[imgTabs resizableImageWithCapInsets: UIEdgeInsetsMake(5, 10, 2, 0) resizingMode: UIImageResizingModeTile];
img.image= imgTabs;
}
}
else
{
NSArray *fetchedNewsCategory = [appDelegate getNewsCategoryByName:text];
if(fetchedNewsCategory.count > 0)
{
for (int t=0; t<fetchedNewsCategory.count; t++) {
News_Categories *catList = [fetchedNewsCategory objectAtIndex:t];
NSString *titleImage = [self URLEncodeString:[NSString stringWithFormat:#"%#",catList.category_image]];
NSURL *url = [NSURL URLWithString:titleImage];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *imgTabs = [UIImage imageWithData:data];
// [header2 setImage:imgTabs forState:UIControlStateNormal];
[imgTabs resizableImageWithCapInsets: UIEdgeInsetsMake(10, 10, 2, 0) resizingMode: UIImageResizingModeTile];
img.image= imgTabs;
}
}
else
{
NSArray *fetchedCompetition = [appDelegate getCompetitionByName:text];
if(fetchedCompetition.count > 0)
{
for (int t=0; t<fetchedCompetition.count; t++) {
Competitions_List *catList = [fetchedCompetition objectAtIndex:t];
NSString *titleImage = [self URLEncodeString:[NSString stringWithFormat:#"%#",catList.competition_tab_image]];
NSURL *url = [NSURL URLWithString:titleImage];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *imgTabs = [UIImage imageWithData:data];
// [header2 setImage:imgTabs forState:UIControlStateNormal];
[imgTabs resizableImageWithCapInsets: UIEdgeInsetsMake(10, 10, 2, 0) resizingMode: UIImageResizingModeTile];
img.image= imgTabs;
break;
}
}
}
}
categoryTitle.textColor = color;
[labelView addSubview:img];
[labelView addSubview:categoryTitle];
[self.contentView addSubview:labelView];
UIView *labelView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, kCategoryLabelHieght)];
You are defining a UIView but allocating a UILabel. iOS 8 is less tolerant to errors like this. Try to change it to
UIView *labelView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, kCategoryLabelHieght)];