I having scroolViewController having UIImageView and UITextView.so how we fatch the UItextView text and image of UIImage.it gives error...
for(UIView *subview2 in [scroolViewController subviews])
{
NSLog(#"-----%#",subview2);
if([subview2 isKindOfClass:[UIImageView class]])
{
[dictImages setValue:subview2.image forKey:#"positionY"];
}
if(subview2 isKindOfClass:[UITextView class])
{
[dicText setValue:subview3.text forKey:#"text"];
}
}
Or when we writhe this
for(UIView *subview2 in [scroolViewController subviews])
{
NSLog(#"-----%#",subview2);
}
then console gives:
-----<UITextView: 0xb8791d0; frame = (5 10; 285 340); text = ''; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0xb860a30>; contentOffset: {0, 0}>
-----<UIImageView: 0xb0c9d10; frame = (134 118; 100 100); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xb0c8600>>
so how we save text and image dictionary from getting subviews...????
To fix the compiler error, do:
[dictImages setValue:((UIImageView*)subview2).image forKey:#"positionY"];
Since you've already checked that it's the right class, casting it is fine.
Is dictImages an NSMutableDictionary?
Related
I am a beginner in iOS. i have created a UIScrollview with 5 images and set its width, height and size change according to orientation. After adding all 5 images the scroll view subview count is 5. But when start dragging the count increases to 7. I don't know where the blank view is added.
CODE
-(void)addImageWithName:(NSString*)imageString atPosition:(int)position {
UIImage *image = [UIImage imageWithContentsOfFile:imageString];
imageView = [[UIImageView alloc] initWithImage:image];
// imageView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
imageView.frame = CGRectMake(position*scrollview.frame.size.width*2, 0, scrollview.frame.size.width *2,scrollview.frame.size.height );
imageView.tag = 1000 + position +1;
[scrollview addSubview:imageView];
}
-(void)imageLoad:(NSInteger)startImage
{
int Index = -1;
for (UIImageView *subview in scrollview.subviews)
{
[subview removeFromSuperview];
}
for (int i = startImage; i < startImage+5; i++) {
Index++;
fullPath = [dataPath stringByAppendingString:[NSString stringWithFormat:#"/image%d.jpg",i]];
[self addImageWithName:fullPath atPosition:Index];
scrollview.contentSize = CGSizeMake(i*scrollview.frame.size.width, 0);
}
}
When you start scrolling, the scrollbar views are added temporarily as subviews.
I want to show movie player controls when the movie is finished, so I add observer to NSNotificationCenter :
- (void)movieFinishedCallback:(NSNotification*)aNotification
{
// Obtain the reason why the movie playback finished
NSNumber *finishReason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
if ([finishReason intValue] == 0)
{
[self showControls];
}
// Handle other reasons
}
- (void)showControls
{
for(id views in [[[self.playerVC moviePlayer] view] subviews]){
for(id subViews in [views subviews]){
for (id controlView in [subViews subviews]){
[controlView setAlpha:1.0];
[controlView setHidden:NO];
}
}
}
}
till now every thing is working well and the controls were appeared, but when I tap on the screen in order to hide them, the controls disappeared and appeared again quickly (something like flash), then I need to tap again on the view to hide the controls ..
anybody knows why I got this issue ? or has another idea to show the controls when the video is finished ?
First debug and print the subviews of the MPMoviePlayerView and write down the subviews and find the name of the control view.
This is the debugging i got in my app.
Printing description of subViews:
<MPVideoContainerView: 0x7f936950f6e0; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7f936950fa30>>
Printing description of controlView:
<MPVideoPlaybackOverlayView: 0x7f9369659a70; frame = (0 0; 375 667); alpha = 0; hidden = YES; autoresize = W+H; tag = 1004; layer = <CALayer: 0x7f93696c4710>>
Printing description of subViews:
<MPVideoContainerView: 0x7f936950f6e0; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7f936950fa30>>
Printing description of views:
<MPSwipableView: 0x7f9369510290; frame = (0 0; 375 667); autoresize = W+H; gestureRecognizers = <NSArray: 0x7f9369510d30>; layer = <CALayer: 0x7f9369510620>>
Then i just checked the name of the control view and removed it form the player. Set it to hidden.
- (void)hideControls
{
for(id views in [[player view] subviews]){
for(id subViews in [views subviews]){
for (id controlView in [subViews subviews]){
if ( [controlView isKindOfClass:NSClassFromString(#"MPVideoPlaybackOverlayView")] ) {
[controlView setAlpha:0.0];
[controlView setHidden:YES];
}
}
}
}
}
I want to set my custom image for UITableView scrollbar.
For that i found this link: WKVerticalScrollBar for iOS
But it seems too complex to implement. It is just an image for TableView scrollbar.
Is there any other easy way to do that?
UPDATE - 1
My Tableview has only these 2 subviews
"<UIImageView: 0x6c2c9f0; frame = (0 778; 360 7); alpha = 0; opaque = NO; autoresize = TM; userInteractionEnabled = NO; layer = <CALayer: 0x6c2ca60>>",
"<UIImageView: 0x6c06680; frame = (353 778; 7 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x6c2be70>>"
With that i Have tried with both index but any of it not working
tblvw.showsVerticalScrollIndicator = YES;
NSLog(#"tblview subview : %#",tblvw.subviews);
UIImageView *imgview = [tblvw.subviews objectAtIndex:0];
imgview.image = [UIImage imageNamed:#"Slider-strip.png"];
After making tblvw.showsVerticalScrollIndicator = NO;
I came to know that i was not getting the 2nd imageview as subview & only 1st imageview. So i tried using [tblvw.subviews objectAtIndex:1]; but also not working
Working Perfectly:
EDIT : Note: Best implementation is to have Vertical Image. For example like.............................................
if([self.tableView.subviews count] > 2){
UIImageView *scrollViewBarImgView = [self.tableView.subviews objectAtIndex:2];
UIImage *imgBar = [UIImage imageNamed:#"image.png"]; //your image here
[scrollViewBarImgView setImage:imgBar];
}
else{
UIImageView *scrollViewBarImgView = [self.tableView.subviews objectAtIndex:1];
UIImage *imgBar = [UIImage imageNamed:#"image.png"]; //your image here
[scrollViewBarImgView setImage:imgBar];
}
I've got myself totally baffled with this scrollview. For some reason, on the third pass of this loop, an extra two UIImageViews get added as subviews. I assume i'm addressing bad memory, or something to that effect, but I can't figure out where it is coming from for the life of me.
Here's the code:
scrollview=[[[UIScrollView alloc] initWithFrame:CGRectMake(x, y+40, 300, 225)] retain];
NSArray *chunks=[lesson.photoString componentsSeparatedByString:#"|"];
ALAssetsLibrary *assetLibrary;
__block CGRect workingFrame = scrollview.bounds;
__block UIImageView *imageview=nil;
workingFrame.origin.x = 0;
NSLog(#"Chunks: %d\n",[chunks count]);
for(NSString *url in chunks) {
//
if(url && [url length])
{
NSURL *asseturl = [NSURL URLWithString:url];
assetLibrary = [[[ALAssetsLibrary alloc] init] autorelease];
[assetLibrary assetForURL:asseturl
resultBlock:^(ALAsset *myasset)
{
UIView *sub=[[UIView alloc] initWithFrame:workingFrame];
imageview=[[UIImageView alloc] initWithImage:[UIImage imageWithCGImage:[[myasset defaultRepresentation] fullScreenImage]]];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
imageview.frame = sub.bounds;
[sub addSubview:imageview];
[imageview release];
UIButton *imgfull=[UIButton buttonWithType:UIButtonTypeCustom];
[imgfull setFrame:sub.bounds];
imgfull.backgroundColor=[UIColor clearColor];
[imgfull addTarget:self action:#selector(imageViewToFullScreen) forControlEvents:UIControlEventTouchUpInside];
[sub addSubview:imgfull];
[imgfull release];
[scrollview addSubview: sub];
[sub release];
NSLog(#"%#",[scrollview subviews]);
workingFrame.origin.x = workingFrame.origin.x + workingFrame.size.width;
[scrollview setContentSize:CGSizeMake(workingFrame.origin.x, workingFrame.size.height)];
if(scrollview.contentSize.width>300)
[scrollview flashScrollIndicators];
}
failureBlock:^(NSError *myerror){
NSLog(#"Failure - %#",[myerror localizedDescription]);
}
];
}
}
[scrollview setPagingEnabled:YES];
[self.view addSubview:scrollview];
Here's the output:
2011-05-04 11:53:00.331 AppName[24896:207] Chunks: 4
2011-05-04 11:53:00.369 AppName[24896:207] (
"<UIView: 0x6685960; frame = (0 0; 300 225); layer = <CALayer: 0x6685990>>"
)
2011-05-04 11:53:00.394 AppName[24896:207] (
"<UIView: 0x6685960; frame = (0 0; 300 225); layer = <CALayer: 0x6685990>>",
"<UIView: 0x642db00; frame = (300 0; 300 225); layer = <CALayer: 0x6420c80>>"
)
2011-05-04 11:53:00.426 AppName[24896:207] (
"<UIView: 0x6685960; frame = (0 0; 300 225); layer = <CALayer: 0x6685990>>",
"<UIView: 0x642db00; frame = (300 0; 300 225); layer = <CALayer: 0x6420c80>>",
"<UIImageView: 0x666e3d0; frame = (292 1; 7 223); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x666e400>>",
"<UIImageView: 0x6605490; frame = (1 217; 149 7); opaque = NO; autoresize = TM; userInteractionEnabled = NO; animations = { opacity=<CABasicAnimation: 0x6686ff0>; }; layer = <CALayer: 0x6664280>>",
"<UIView: 0x6686c30; frame = (600 0; 300 225); layer = <CALayer: 0x6686c60>>"
)
2011-05-04 11:53:00.439 AppName[24896:207] (
"<UIView: 0x6685960; frame = (0 0; 300 225); layer = <CALayer: 0x6685990>>",
"<UIView: 0x642db00; frame = (300 0; 300 225); layer = <CALayer: 0x6420c80>>",
"<UIImageView: 0x666e3d0; frame = (292 1; 7 223); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0x666e400>>",
"<UIView: 0x6686c30; frame = (600 0; 300 225); layer = <CALayer: 0x6686c60>>",
"<UIImageView: 0x6605490; frame = (1 217; 99 7); opaque = NO; autoresize = TM; userInteractionEnabled = NO; animations = { opacity=<CABasicAnimation: 0x6648d60>; }; layer = <CALayer: 0x6664280>>",
"<UIView: 0x6673f90; frame = (900 0; 300 225); layer = <CALayer: 0x6673fc0>>"
)
EDIT: I should also mention that I've NSLog'd sub, and it produces the results I'd expect (1 imageview, 1 button per trip through the loop). I should also mention, that as far as I know I have no imageviews of the dimensions shown from the scrollview logging (99x7 or 7x223) anywhere in my app.
EDIT 2: A bit further information: I switched the add line to [scrollview addSubview:nil]; and I'm still seeing two imageviews being added on the third pass of the loop. Also, scrollview isn't accessed from anywhere else outside the posted code section.
EDIT 3: Figured out out. I'm flashing the scrollbars too early, which is mucking with the order of the subviews within the scrollview.
Are these the scroll view indicators flashing?
If no unusual images actually appear on your scroll view, you can assume those subviews are managed internally by UIScrollView and you should ignore them. Scroll indicators, perhaps.
Actually These extra two images are the uiscrollindicator images that are vertical scroll indicator and horizontal scroll indicator with tag 0 That are added by UIScrollview Automatically , if you add UIIMageViews to the ScrollView make sure to assign tag greater than zero, or use some other technique , so that you can retrieve your UIIMageViews by tag greater than zero..
I have the following code
// Breakpoint here
[label removeFromSuperview];
[label release];
label = nil;
stepping through it with the debugger outputs
(gdb) po [self subviews]
<NSCFArray 0x476af70>(
<UIImageView: 0x47581a0; frame = (0 0; 232 81); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x476b3d0>>,
<UILabel: 0x4758870; frame = (15 11; 202 56); text = 'Test'; clipsToBounds = YES; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x476b590>>
)
(gdb) po label
<UILabel: 0x4758870; frame = (15 11; 202 56); text = 'Test'; clipsToBounds = YES; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x476b590>>
(gdb) n
(gdb) n
(gdb) n
(gdb) po [self subviews]
<NSCFArray 0x478c4e0>(
<UIImageView: 0x47581a0; frame = (0 0; 232 81); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x476b3d0>>
)
Yet it is still visible, it does not disappear. Not even if I do [self setNeedsDisplay] immediately after.
Has anyone else come across this? Is it a bug in the SDK or am I missing something?
It turns out a bug in my code elsewhere was causing multiple identical views to be created on top of each other, leading to this behaviour.