i have a viewcontroller with a textview and a label and i want to change the text on both of them before i load the view.
- (IBAction)loadCardInformation:(id)sender{
ciViewController = [[CardInformationViewController alloc] initWithNibName:#"CardInformationViewController" bundle:nil];
[ciViewController.infoLabel setText:#"ROFL"];
[ciViewController.infoText setText:#"CAKE"];
[self.view addSubview:(UIView *)ciViewController.view];
}
I have hooked both the label and the textview to outlets, but nothing is changing.
You need to set these in viewDidLoad of the viewController. At the point where you are currently setting the properties they have not been loaded.
Also
[self.view addSubview:(UIView *)ciViewController.view];
this looks like something you should most likely not be doing.
Related
I have the following code in viewDidLoad on my ViewController:
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:204.0/255 green:00.0/255 blue:00.0/255 alpha:1];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"background.png"]];
autoNameLabel.text = (NSString *)[vendorDetails objectForKey:#"autoname"];
homeLabel.text = (NSString *)[vendorDetails objectForKey:#"homelab"];
descriptionTextView.text = (NSString *)[vendorDetails objectForKey:#"description"];
This all fits perfectly on the view. I know need to add an additional textView on the bottom so need the user to be able to scroll to see it. How can I add this info to a scrollable view and add my additional textView?
you could have your UIViewController extend UISCrollViewController. Or you could add a UIScrollView to your view controller's view in the method viewDidLoad. Then add all subviews of your view to the scrollview instead.
self.scrollView = [[UIScrollView all] initWithFrame:self.view.bounds]
self.scrollView.contentSize = CGSizeMake(self.scrollView.bounds.width, HEIGHT_OF_SCROLLABLE_AREA).
I would also do something like this for the scroll view height if your last textview is named lastTextView
HEIGHT_OF_SCROLLABLE_AREA = CGRectGetMaxY(lastTextView.frame + bottomPadding)
Are you sure you dragged all the other views on the scrollview? Make sure the contentSize of the scrollview is high enough(you know, higher than the screen) to scroll.
have u set delegate of UIScrollView. if you have not set delegate of UIScrollView then also it may possible that your scroll is not working.
I have added a subview over my UITableView using:
TransparentViewController *tvc =
[[TransparentViewController alloc]
initWithNibName:#"TransparentViewController" bundle:nil];
[self.view addSubview:tvc.view];
My Nib has a UIImageView in it that has some text and a transparent background.
When I load the detailView for the table for the first time I show the subview that gives a brief explanation of the information that you can see below the text. Works really well.
What i would like to do is alter the alpha of the underlying table so that it is dimmer but not affect the alpha of the overlay subview. If i use:
[self.view setAlpha:(CGFloat)];
It dims the overlay as well. I seem to be having a mental block.
Changing the alpha affects the subviews as well. Your tvc.view is a subview of self.view, so it is naturally going to be affected.
Why don't you try this: put another view in tvc.view and send this view to this view to the back.
(UIView*) back = [[UIView alloc] initWithFrame:CGFrameMake(...)];
back.backgroundColor = [UIColor grayColor]; // choose a color that you like;
back.alpha = 0.5; // whatever works for you
[tvc.view addSubview:back];
[tvc.view sendSubviewToBack:back];
Set the size and alpha of this new view to something you like. The table view will show through it to a limited extent, which may accomplish what you are trying to do.
Since this is part of our tvc view, it will appear when you show that view and go away when you hide that view.
I have an app where it reads an XML document containing 2 fields (image url and description). If the document has a field that has a valid image URL, I want the view to show the image. Else I just want it to show the description.
The problem I am having is :
how to show the UIImageView dynamically
how to move the UITextView downwards since now I added a UIImageView
Currently I just have a View with a UITextView on it.
Any ideas?
1) -[UIView setHidden:] if the UIImageView is already in place. Otherwise, [[UIImageView alloc] initWithFrame:], then add the image view as a subview to the view.
2) -[UIView setFrame:] (is one option)
The following is what you could do.
Prepare the the view with the UIImageView and the UITextView in the viewDidLoad like this:
-(void) viewDidLoad)
{
[super viewDidLoad];
myImageView = [[UIImageView alloc] init];
myImageView.frame = CGRectMake(x,y,0,0); //you can set it at the right position and even set either the width OR the height depending on where you want the textView in my example I'm gonna assume its beneath the imageView
//other imageView settings
[myView addSubView:myImageView];
myTextView = [[myTextView alloc] init];
myTextView.frame = CGRectMake(x,y,width,heigh+CGRectGetMaxY(myImageView.frame)); //here you prepare the textView for the imageView and the space it takes. But doesn't get hindered by it if it's not there.
//other textView settings.
[myView addSubView:myTextView];
//You would want this loading function about here OR after this loading has been occured.
[self loadImageFromURL];
}
-(void)loadImageFromURL
{
//get your image here.. or not
if(imageHasLoaded) //some condition that gets set when your image has successfully loaded. (This should be done in a delegate (didLoadImageFromURL) if you have such thing prepared.
{
//myImageView.image = theLoadedImage;
myImageView.frame = CGRectMake(x,y,theLoadedImageWidth,theLoadedImageHeight);
//after you set the frame of the imageView you need to refresh the view
[myView setNeedsDisplay];
}
}
And this is how you should dynamically add an imageView with image and frame to some view.
I've seen this question asked around before, and found an answer for how to do this in a simple view. But... when I go to a subsequent view pushed onto the view stack, manually setting the titleView doesn't work out. The titleView view gets pushed off to the right while the back button and its text take over the left half of the UI.
Is there a standard way to do this? I've noticed the Gowalla app apparently does it quite well. I've tried a multitude of approaches including categories, subclasses, etc and haven't had any luck.
Every UIViewController has it's own navigationItem, which (potentially) has a titleView. When you push and pop view controllers in a navigation control, the parts of the navigationItem are what you are seeing. If you wanted a custom title color, you could very easily do something like the following in each of your view controllers.
- (UINavigationItem *)navigationItem
{
UINavigationItem *navigationItem = [super navigationItem];
UILabel *customLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320.0f, 44.0f)];
customLabel.text = #"My Title";
customLabel.textColor = [UIColor purpleColor];
navigationItem.titleView = customLabel;
[customLabel release];
return navigationItem;
}
I have a UIViewController (ContentViewController) wired to a View xib. I drop a TextView on the UIView and it appears as a subview in the hierarchy in IB.
ContentViewController has a label as an outlet, which is wired to a label on ContentView.xib. When the code below executes, the first view shows the text view but scrolling through the other views/pages reveals only the label.
for(int i=0; i< 5; i++){
ContentViewController *contentView = [[ContentViewController alloc] initWithNibName:#"ContentView" bundle:[NSBundle mainBundle]];
[contentView loadView];
contentView.theLabel.text =[NSString stringWithFormat:#"hello again..%d", i];
[self.scrollView addSubview:contentView.view];
}
I can drag a button or textfield onto the view in IB and they are all there as I scroll through pages. The above text is set on the label as well. The textview disappears after the first page. I also can't set its text. I've dragged a new textview onto the UIView and it disappears after the first page as well. Is there something different I need to do for the textview?
I've found that the UIScrollView is on each page. If I swipe vertically where the scrollview is, text will appear. But I have to do that for all scrollviews after the first one.
However, once I swipe them, the text remains visible until the app is restarted. If there isn't enough text to cause scrolling, the textview will never appear. Any suggestions on this behavior?
Try :
[textView setNeedsDisplay];
Original Answer
You wouldn't have to deal with the textview differently.
I first worry about your calling of "loadview". You are never supposed to call that directly. It is invoked automtically when needed.
Also, you should declare contentview before the loop and you are leaking memory.
Your other problem is you never change the frame of each view during the loop. They all have an origin of {0,0}. As far as I can see from your code. This may be why your views are hidden.
Lastly, on a style note, I wouldn't call me view controllers XXXXXview, they should have the word controller in them.
CGRect frame;
ContentViewController *myContentViewController = nil;
for(int i=0; i< 5; i++){
myContentViewController = [[myContentViewController alloc] initWithNibName:#"ContentView" bundle:[NSBundle mainBundle]];
frame = myContentViewController.view.frame;
frame.origin.x=(frame.size.width*i);
myContentViewController.view.frame=frame;
myContentViewController.theLabel.text =[NSString stringWithFormat:#"hello again..%d", i];
[self.scrollView addSubview: myContentViewController.view];
[myContentViewController release];
}
To Add:
Also check the scrollviews contentView frame property:
scrollView.contentSize = CGSizeMake(numberOfContentViews*contentViewWidth, contentViewHeight);
To add more:
Try adding the textView programatically in viewDidload or viewDidAppear to see if that works.
After your comments, if I had to take another guess, I would say that you might be manipulating the textView somewhere else in your code after it is added. Start commenting out any lines that affect the textView and see what happens.