04-08-2011, 01:47 AM
#1 (permalink )
Registered Member
Join Date: Apr 2011
Posts: 9
Horizontal UIScrollView like in BBC News app?
Hello!
Im trying to make News scroll like in BBC News app
bbc-news-app.jpg
I've made class Slider: UIScrollView and custom TapView: UIView for every news entry.
Its working but I cant access to my TapView to change title label or description label from Slider or ViewController.
So in my custom UIView class TapView i have this:
Code:
@interface TapView : UIView {
NSString *titleFeed; // Name of the source feed
NSString *img; // Feed entry image
NSString *description; // Feed entry title
NSString *url; // Feed entry url
UILabel *titleView;
UILabel *descView;
UIImageView *imageView;
BOOL isActive;
}
@property (retain) NSString *titleFeed;
@property (retain) NSString *img;
@property (retain) NSString *description;
@property (retain) NSString *url;
@property (retain) UILabel *titleView;
@property (retain) UILabel *descView;
@property (retain) UIImageView *imageView;
@property (nonatomic, assign) BOOL isActive;
In implementition i have:
Code:
@synthesize titleFeed, img, description, url, titleView, descView, imageView, isActive;
- (id)initWithFrame:(CGRect)frame {
CGRect newFrame = CGRectMake(0.0f, 0.0f, 160, 200);
self = [super initWithFrame:newFrame];
if (self) {
CGRect titleViewFrame = CGRectMake(10.0f, 0.0f, 150, 15);
CGRect imageViewFrame = CGRectMake(0.0f, 20.0f, 160, 96);
CGRect descriptionViewFrame = CGRectMake(10.0f, 120.0f, 150, 39);
UILabel *temptitleView = [[UILabel alloc] initWithFrame:titleViewFrame];
self.titleView = temptitleView;
[temptitleView release];
UIImageView *tempimageView = [[UIImageView alloc] initWithFrame:imageViewFrame];
self.imageView = tempimageView;
[tempimageView release];
UILabel *tempdescView = [[UILabel alloc] initWithFrame:descriptionViewFrame];
self.descView = tempdescView;
[tempdescView release];
[self addSubview:titleView];
[self addSubview:imageView];
[self addSubview:descView];
}
return self;
}
Cant get access to my UILabels text property. its not changing some how. Any ideas?
Or maybe you know how to organize code more efficiency?
Last edited by Grance; 04-08-2011 at 01:58 AM .
04-08-2011, 03:44 AM
#2 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
what mean exactly that you can't access UILabel? can you do an example of what are not working?
__________________
04-08-2011, 04:05 AM
#3 (permalink )
Registered Member
Join Date: Apr 2011
Posts: 9
for example in my ViewController i've added:
Code:
TapView *t = [[TapView alloc] initWithFrame:scrollViewRect];
NSString *p = @"Lalala";
t.titleView.text = p;
t.descView.text = p;
[self.scrollView addSubview:t];
[t release];
UILabels are empty
04-08-2011, 04:57 AM
#4 (permalink )
Registered Member
Join Date: Apr 2011
Posts: 9
NSLog(@"%@, %@", t.feedLabel.text, t.descView.text);
show me that both of them have that NSString p value, but they dont show-up on the screen.
*I've figured out that I needed to init UILabels with empty strings, now it's working
1. But how do you think am I need all this NSStrings in class TapView, or it is better do access directly to UILabels of TapView class?
2. If I have an array of TapViews, and user touched one of them how can I make it active (for example i can make border around touched TapView)? I'll have to loop through all of them except that one thouched and their borders to none? Or there is more simple way to check it?
04-08-2011, 05:22 AM
#5 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
i think was a problem related to update your view (with a setNeedDisplay), but i'm not sure, if someone know why worked only after initialized with a string, i wish to know
.
1) yes, you should access directly the label, create a NSString for that doesn't make sense, you can do a method if you need to do some checks before setting text.
2) you should do the opposite, draw a rect on your custom UIView when user tap it.
__________________
Last edited by dany_dev; 04-08-2011 at 05:35 AM .
04-08-2011, 11:58 AM
#6 (permalink )
Registered Member
Join Date: Apr 2011
Posts: 9
ok! Thank you for reply!
04-10-2011, 01:44 AM
#7 (permalink )
Registered Member
Join Date: Apr 2011
Posts: 9
I have one more question ^)
If i have TapView button and I have url stored in that class with how can I pass it from TapView to UIWebView class throught UIViewController?
Some delegate methods or there is a simpler better way?
04-13-2011, 09:53 AM
#8 (permalink )
Registered Member
Join Date: Apr 2011
Posts: 9
Anyone?
How can i make working delegation?
04-13-2011, 12:04 PM
#9 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
how you "intercept" the touch on your TapView?
__________________
04-13-2011, 12:58 PM
#10 (permalink )
Registered Member
Join Date: Apr 2011
Posts: 9
Holly cow! I've get it working while writing answer to you
Thank you!
Last edited by Grance; 04-13-2011 at 01:01 PM .
04-13-2011, 01:27 PM
#11 (permalink )
Nuisance Developer
Join Date: Jul 2009
Location: Italy
Posts: 4,691
__________________
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 357
13 members and 344 guests
dansparrow , dre , ilmman , LezB44 , michelle , Nobbsy , Objective Zero , samdanielblr , Sami Gh , shagor012 , sledzeppelin , thephotographer , tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44