Force a UITextView to redisplay after changing contentInset? - iphone

I change the contentInset. How can I force it to update the display to reflect the new value?

I found that it did update the contentInset immediately, but it didn't look like it because it adjusts the location that the UITextView is scrolled to such that the display of the UITextView doesn't change.
By scrolling back to the top-left corner, it has the effect I think you're looking for of updating the display with the new content inset:
[textView scrollRectToVisible:CGRectMake(0,0,1,1) animated:NO];

I have a similar issue if not the same issue.
I was able to get setNeedsDisplay to work, but you have to use it and place it on the right view and call it in the right order or it won't work.
I have a view that I want to reuse, all I change is a UITextView and an image on the view depending on where it is opened from. I have the label accessible via Outlet on the controller. I could tell that my assignment was working as the changed value would show up the 2nd time I went back to the modified view. I could not get any of the previously suggested ways to work until I hooked up setNeedsDisplay on the controllers view (NOT the UITextView, as I tried that and it did not take) and I had to do it just before I make the text change as it did not work if I made the call after the setText. Anyway, maybe setting it up in this way and in that order may work for you.

Try using [textView setNeedsDisplay].

The only way I could think of is to re-init it with the new properties. Sounds like a waste, though.

You could also try [textView layoutIfNeeded] or [textView layoutSubviews].
I take it back, the documentation of this method suggests that:
The default implementation of this
method does nothing.
and
You should not call this method
directly.

Does [textView setNeedsLayout] do it?

Related

UISegmentedControl Not Redrawn

I'm using a UISegmentedControl to show headers for a table view. When the orientation changes, the headers are resized depending on the labels in the table view underneath. Despite being connected up in IB, I have to move the phone around a bit to fire a orientationChanged notification and update the widths. I've even tried setting the first segment width to 0 in IB, then again in viewDidLoad, but all headers are the same width when the view loads. I've tried using performSelector:afterDelay to make sure the view is actually on screen, and also calling setNeedsLayout and setNeedsDisplay, but nothing seems to work. I simply have to jiggle the phone around.
Is this a bug anyone has experience with or am I making a daft mistake?
I'm setting the width as below:
[segSortOrder setWidth:0.0 forSegmentAtIndex:0];
The only solution I came up with for this was to use performSelector:afterDelay and using self.view.bounds.size.width with a variable amount of padding (how much is trial and error for each ViewController. Not ideal but it does the job.

I want to redraw a view

I want to redraw a view.
When I touch a button, my view have to redraw itself. (have to call viewWillAppear)
But view's setNeedDisplay method doesn't redraw itself immediately.
Because I have to redraw it immediately, the method is not suitable to me.
I tried to remove all of viewController's view's subviews and to change viewController's
view to other view.
But these didn't work. (don't redraw)
I need your help acutely.
Thank you for your reading.
I think there are some misunderstandings here. Let's set things straight:
viewWillAppear: has nothing to do with the drawing of the view.
It's true that setNeedsDisplay doesn't redraw the view instantly, but we're talking milliseconds. So that's not even relevant.
Since you want viewWillAppear: to be called I'm assuming that what you call redrawing the view really should be referred to as relayouting the view. I assume that what you do in viewWillAppear: is setting the frames of you're views and possibly add/remove and/or show/hide some views.
I suggest that you move that code out of viewWillAppear: and into it's own method that will be called from viewWillAppear: and when you tap the button.
Since you don't provide your viewWillAppear: code this is all based on assumptions, so if my assumptions are wrong, please let me know and please do provide your "redraw" code.
Without more details it's hard to know exactly what you need but I might suggest you look at UIView::setNeedsDisplay. This will in turn cause your views drawRect: to be called where you can update the drawing.
[yourViewName setNeedsDisplay];

Remove a UITextField from a view

how can I remove a UITextField from a View? I've assigned a tag to the UITextfield and I search it from the subviews in the main view. But when I found it, it do a strange thing: doesn't execute the after instruction, or exactly it execute the instruction, but do nothing. Instead if I hidden it, all works fine.
Why won't you use removeFromSuperview selector?
You should by able to completely remove the UITextField by calling - (void)removeFromSuperview on the main thread.
You can remove your views by using removeFromSuperview
and should be like ---> [myTextView removeFromSuperview]
I think there might be other views over UITextView.Since
[myTextView removeFromSuperview];
should work fine.You can remove any of the view which is in SuperView.
So, please make sure that UITextView is still there ....or from somewhere else still textView is allocated & added to subivew.
Either you can set the Different BackGround Colors for TextView so that you can easily trace whether what is removed from SuperView.

UICatalog and Keyboard Events

The latest version of Apple's UICatalog example application includes zero code in the TextFieldController for handling keyboard show/hide events, and yet the table view still slides up and down beautifully with the keyboard.
Does anyone know what the new trick is? Are there settings in the XIB that allowed them to forgo registering for the notifications or using TextField delegate methods?
The TextViewController still uses keyboard notifications to deal with view sliding, so I'm really confused as to why this isn't included for TextFields anymore.
Thoughts?
You can close the keyboard, if it's open by calling:
[sender resignFirstResponder];
Not sure about opening the keyboard however.
The trick is hidden within calling becomeFirstResponder on a UITextField that is in a scrollable view. Apparently, whenever calling [textField becomeFirstResponder], iOS automatically scrolls the parent view until said textField is visible.
This behavior can actually be undesirable in some cases, as it will not usually scroll to the same location that the UIScrollView method scrollRectToVisible:animated: would if you were to try to do things that way.
Thanks for your thoughts everyone!

Floating a UILabel above OpenFlow

How do you get a UILabel to float above Alex Fajkowski's implementation of CoverFlow called OpenFlow?
Ok I've figured it out. I just had to use bringSubviewToFront with the UILabel.
Thanks to everybody who answered.
Make an OpenFlow instance and a UILabel instance subviews of a parent view, placing the label atop with flow view using -insertSubview:atIndex:, -addSubview: or similar e.g.:
[self.view addSubview:myOpenFlow];
[self.view addSubview:myLabel];
To answer the second question, try this: edit the AFOpenFlowView in IB and add the label view as a subview of that wherever you want it to appear, then set the attributes on the view to Hidden if you don't want it to appear by default. Create an IBOutlet for the label view in your controller so you can easily manipulate it, such as setting hidden to show in order to show it. I'm not familiar with open flow so I'm not sure if it will programmatically create a subview that will obscure your label. If so you may need to use the outlet to move it to the front using UIView methods.
The Openflow example code shows a perfect demonstration of this. Alex adds an info button in the top right of the openflow view using interface builder. This is exactly what you are asking for.
I would add that if you can't understand what is going on from the example code, you should look at more code examples from Apple demonstrating simple UIView usage.
It's not so easy because the label name has to change for each picture. We have to work with index, and with event.. move.. tap.. selected...I'm working on too !