UIScrollView stops working when label text in UIScrollView is changed - iphone

I have had this problem for a long time now, I hope stackoverflow can help!
THE PROBLEM IS
When I enter "Alan Shearer" into the EnterNameText (UI TEXTFIELD) the label changes text, however the ScrollView no longer scrolls to the set content size, it will scroll a little bit, but no were near the set content size, in this case 2000px in height.
details
1) Xcode 4.5.1
2) IOS 6
In my .xib file ( tinypic.com/view.php?pic=2h4yx3o&s=6 ) I have a UIScrollView (320 pixels in width, and 490 pixels in height)
The UIScrollView contains labels that are all connected to view controller.h.
The Label (all labels are set in the same way) :
#property (strong, nonatomic) IBOutlet UILabel *AlanShearerLabel;
my UIScrollView in ViewController.h looks like this:
#property (strong, nonatomic) IBOutlet UIScrollView *scrollview;
UIScrollView in ViewController.m
- (void)viewDidAppear:(BOOL)animated{[super viewDidAppear:animated]; self.scrollview.contentSize=CGSizeMake(320.0, 2000.0); }
An IBAction called - (IBAction)CheckButton:(id)sender
The action when CheckButton is clicked:
//string 0
NSString *string0 = _EnterNameText.text;
//Alan Shearer
NSString *string1 =#"Alan Shearer";
NSString *string2 =#"Rank 1) Alan Shearer 260 Goals";
NSString *stringshearer =#"Shearer";
//Alan Shearer IF
if([string0 isEqualToString:string1]||
[string0 isEqualToString:stringshearer])
{_AlanShearerLabel.text = string2;
_AlanShearerLabel.textColor = [UIColor greenColor];
_EnterNameText.text=#"";
}

To solve this issue you must be sure to define all the things inside the scrollview before you link the scrollview to the .h file. For example if you have 20 labels in a scrollview, be sure that the 20 labels have been connected to the .h file, set the right size, put in the right place. Only then do you connect your scrollview to the .h file and place the scrollview code in viewDidAppear rather then viewdidload.

Related

How to add text area in iOS app

I am newbie for iPhone application. I want to add TextArea. I know how to add textField, however can someone help me how can I have Textare in my iPhone application?
I thought, I can increase the height of textfield and make it multi-line, however that option is not there.
You cannot increase the height of UITextField. for this you need to use UITextView.
In your Interface builder where you got UITextField, there is also an option of UITextView.
you can use UITextView same as UITextField in iPhone. UITextView is used for multiple lines
UITextView *txt = [[UITextView alloc]init];
//set frame
//add on view
[self.view addSubView:txt];
[txt release];
I hope this solves your problem Sample Code for TextView
UITextView *txt = [[UITextView alloc]initwithframe:CGRectMake(x, y, width,height)];
[self.view addSubView:txt];
[txt release];
You could simply do this by clicking on Mainstoryboard.storyboard or viewController.xib and dragging in a UITextView This will allow multi-line text. If you need to access the Textview, type:
.h file
{
IBOutlet UIITextView *textView;
}
#property (nonatomic, strong) IBOutlet UITextView* textView;
.m file
#synthesize textView;
EDIT
to get the users data, hook up the outlet in storyboards,
then use:
-(void)getUserText{
NSLog#"%#", self.textView);
}
This should print out whatever the user entered into the textView.

Custom TextField With Caption

I am developing an IPhone application and trying to create a custom TextField with caption on it like image below.
As you can see from image Label is changed by the value that user enters or read from database. Also there are other textfields other than name.
I couldn't be sure how should i implement this custom textfield?
One way i think placing an image with "Name:" text to background of textfield and placing "Label" value on it, other way is placing an image with only borders and inserting "Name: Label" text on it.
Are these ways suitable or is there any other best approach available?
Edit: Borders on image are textfield's border; also "Name: Label" is above on textfield.
Simply put another label with the desired text behind or beside the label or text field that is going to be filled. You can set the font and textColor and even the alpha according to your taste.
Make sure that if they overlap (which they should not!) the backgroundColor property of the label is set to [UIColor clearColor].
You could subclass UITextField like this:
#interface LabeledTextField : UIView
#property (nonatomic, strong) UILabel *label;
#property (nonatomic, strong) UITextField *textField;
#end
#define kPercentWidth 0.5
#implementation LabeledTextField
-initWithCoder:(NSCoder)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
CGRect f = self.frame;
_label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,
f.size.width*kPercentWidth,f.size.height)];
_textField = [[UITextField alloc] initWithFrame:CGRectMake(0,0,
f.size.width*(1-kPercentWidth),f.size.height)];
[self addSubView:_label];
[self addSubView:_textField];
}
return self;
}
#end
You could then use it like this: insert a UIView into your storyboard view controller and change the class to your LabeledTextField. This would ensure initWithCoder is called. Otherwise, you might have to put the init code into its own setup function and call it from your override of initWithFrame. Make sure you wire up the view with your outlet
// .h
#include LabeledTextField.h
//...
#property (nonatomic, strong) IBOutlet LabeledTextField *labeledTextField;
// .m, in some method
labeledTextField.textField.text = #"editable text";
labeledTextField.label.text = #"non-editable text";
Similarly, you could modify all properties of the label and text field, including colors, fonts etc.

Fixed footer of a UItableview. always at the footer position

Im trying to have a footer Fixed at the bottom of a uitableview. it will always be at the bottom, not scrollable with the table cells. It also cant cut out and cells like cover the last cell of a uitable view so one cell will be hidden. I have the following header file:
//fooer contains a number_of_total_clicks label, an a proceedtopayment button.
#interface checkout : UITableViewController
#property (retain, nonatomic) IBOutlet UILabel *number_of_total_clicks;
- (IBAction)proceedtonextview:(id)sender;
#property (retain, nonatomic) IBOutlet UIView *footer; //?
#property (strong, nonatomic) NSMutableDictionary *items_clicked;
#end
and in my .m file
- (void)viewDidLoad
{
[super viewDidLoad];
//self.tableView.tableFooterView= footer; ??
number_of_total_clicks.text=#"0";
}
//void or IBAction?V
- (void)add_item_to_array_of_clicks_which_will_increment_number_of_total_clicks_value:(id)sender{
number_of_total_clicks.text=[NSString stringWithFormat:#"$%.2f",[sender doubleValue]*5];
[self.tableView reloadData];
}
What happens is I get a footer the is basically attached to the last cell of the table so if the table has only 3 cells, the "footer" with the number_of_total_clicks will be attached as a 4th cell. if there are 45 cells, he footer will be he 46th cell only accesible once I scroll all the way down. I want it o be fixed a the bottom. Thanks
In your -loadView method try manually creating your view using [UIScreen mainScreen]. applicationFrame as the frame. Note that you should use a UIView, not a table view.
This view will fill the whole screen (except for tab and navbars, when using them).
You can then manually add a UITableView as the VC's tableView, but don't make it fill the whole view. Leave some space at the bottom, just as much to fit your 'table footer' in. Remember to set the tableView to have a flexible width as well as a flexible height.
Now for the 'table footer' just add it as a subview to self.view (not self.tableView) and place it at the very bottom of self.view. This view should have a flexible width and a flexible top margin.
I hope this fits your needs.

Resizing UITableView When Displaying AdWhirl Ads Across Multiple Views

I am trying to integrate AdWhirl into my iPhone app using an AppDelegate singleton so I can use the same AdWhirl instance across multiple views, but cannot figure out how to resize the tables in those views. The code I am using is:
in ...AppDelegate.h:
#import "AdWhirlView.h"
#import "AdWhirlDelegateProtocol.h"
#interface ...AppDelegate : NSObject <UIApplicationDelegate, AdWhirlDelegate>
AdWhirlView *awView;
...
#property (nonatomic, retain) AdWhirlView *awView;
in ...AppDelegate.m didFinishLaunchingWithOptions:
awView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
also in ...AppDelegate.m I add the required delegate methods
(NSString *)adWhirlApplicationKey...
(UIViewController *)viewControllerForPresentingModalView...
This code allows me to display the same Ad across multiple views but I cannot figure out how to resize a UITableView to change its height to be shorter if an Ad is displaying, so that the UITableView either displays full height if there is no Ad, or is resized if there is an Ad at the bottom of the screen. I have the UITableView as a subview of a UIViewController called myMainView.
I tried changing the autosize properties in the Nib file for the UITableView to have a variable spacer at the bottom, and am adding the AdWhirl instance into the view with this code:
...AppDelegate * myDelegate = (...AppDelegate *)[[UIApplication sharedApplication] delegate];
[myDelegate.awView setFrame:CGRectMake(0, 480-20-44-50, 320, 50)];
[self.myMainView addSubview: myDelegate.awView];
This displays the Ad at the correct location at the bottom of the screen but the UITableView is not resizing. How should I be doing this?
I think you have to create a UIView with an embedded UITableView. I've tried to do something similar and this was the only way I could get it to work. A top-level UITableView is auto-resized to take up the entire screen.
Just expanding on that, you probably want to declare something in your header like so:
#interface ExampleClass:UIViewController {
UITableView *tableView;
}
#property (nonatomic,retain) IBOutlet UITableView *tableView;
Then in your actual implementation, you can resize that declared tablview whenever you need to by doing:
CGRect tableFrame = tableView.frame;
//Decrease the height of table by height of ad banner
tableFrame.size.height = tableView.frame.size.height - adBannerView.frame.size.height;
tableView.frame = tableFrame;

tableview image to be display in detailview

DetailsViewController.h
{
UIImageView *Image;
}
#property(retain, nonatomic) IBOutlet UIImageView* Image;
DetailsViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.Title.text = location.title;
self.desc.text = location.description;
this is the code to pull data from plist whenever user select a row in the uitableview..so the problem i am having now is how should i do it if i wan it to display an image?can't seems to get it after a few attempts..greatly appreciate!
if you are looking for just the way to display an image, it is simple.
on Interface Builder,
make Image View
make connection between 1 and Outlet
set the image path (short cut : Command + 1)
If you want to load this image into a UIImageView as suggested by cappucino, setup an IBOutlet like this so you have something to connect it to.
// in your header (.h) file in the interface definition
IBOutlet UIImageView *myIBImage;
// and at the bottom with your property declarations
#property (nonatomic, retain) UIImageView *myIBImage;
Also synthesize it at the top of you implementation file (.m)
#synthesize myIBImage;
Then in Interface Builder make the connections like this http://vimeo.com/3780487
Once connected, you can load the image into memory and set it to the view for your UIImageView.
// load an image from the bundle's path into memory
NSString* tmpStr = #"/myImage.png";
[myIBImageView setImage:[UIImage imageNamed:tmpStr]];
That's it. Who said iPhone coding is hard?
(Yes it is tricky, but you'll do it so often you'll hardly notice!) :D