Objective-c UIScrollView now scrolling nor vertically nor horizontally - ios

I don't understand why my project doesn't work.
I can open the window, but the scrollview wont scroll, which means I can't see the bottom of my UI. Why? I read answers to similar questions but they didn't help me fix my issue.
THIS IS THE DETAILVC.H
#interface DetailVC : UIViewController {
IBOutlet UIImageView *iv_main, *iv_ratings;
IBOutlet UITextField *tf_name, *tf_dob, *tf_age, *tf_weight, *tf_height,*tf_birthplace;
IBOutlet UITextView *tv_description;
IBOutlet UIButton *but_movies, *but_edit;
IBOutlet UINavigationBar *navbar;
IBOutlet UIScrollView *scrollView;
}
#property (nonatomic, retain) IBOutlet UIImageView *iv_main, *iv_ratings;
#property (nonatomic, retain) IBOutlet UITextField *tf_name, *tf_dob, *tf_age, *tf_weight, *tf_height, *tf_birthplace;
#property (nonatomic, retain) IBOutlet UITextView *tv_description;
#property (nonatomic, retain) IBOutlet UIButton *but_movies, *but_edit;
#property (nonatomic, retain) IBOutlet UINavigationBar *navbar;
#property (nonatomic, retain) IBOutlet UIScrollView *scrollView;
#end
THIS IS THE DETAILVC.M
#import "DetailVC.h"
#interface DetailVC ()
#end
#implementation DetailVC
#synthesize iv_main, iv_ratings, tf_age, tf_birthplace, tf_dob, tf_height, tf_name, tf_weight, tv_description, but_edit, but_movies,navbar, scrollView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
scrollView.contentSize = CGSizeMake(320, 1000);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
------Connection Inspector
http://s18.postimg.org/qjzrdz9a1/Schermata_2013_08_07_alle_16_47_19.png
------Scroll View attributed Inspector
http://s8.postimg.org/5eniaq8r9/Schermata_2013_08_07_alle_17_35_04.png

Is there a chance that the frame of your UIScrollView has the same size as contentSize? If yes, the UIScrollView will think it has enough frame to display all of the content.

Related

Unknown type name error in Xcode 6

The goal of my app is to calculate two fields that will return in a text box. Unfortunately I'm receiving an error regarding with unknown type field referring to my TotalField.text field. I have two views. One is the home screen which refers to the second view through a button and the second view contains these fields and labels that I'm trying to target.
This is my code.
ViewController.h
// SalaryCalcApp
//
//
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet UILabel *Total;
#property (strong, nonatomic) IBOutlet UILabel *HourlyRate;
#property (strong, nonatomic) IBOutlet UILabel *NumberOfHours;
#property (nonatomic, strong) UITextField *TotalField;
#property (nonatomic, strong) UITextField *HourlyRateField;
#property (nonatomic, strong) UITextField *NumberOfHoursField;
#end
ViewController.m
// SalaryCalcApp
//
//
//
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#synthesize TotalField;
#synthesize Total;
#synthesize HourlyRate;
#synthesize NumberOfHours;
#synthesize HourlyRateField;
#synthesize NumberOfHoursField;
TotalField.text = [ NSString stringWthFormat: #"%i", (HourlyRateField.text.intValue * NumberOfHoursField.text.intValue) ];
#end
The error resides in this code:
TotalField.text = [ NSString stringWthFormat: #"%i", (HourlyRateField.text.intValue * NumberOfHoursField.text.intValue)];
Error Message:
Unknown type name 'TotalField' and Expected identifier or '('
Thank you everyone for your contributions.
Why is that code not nested inside a function?
Put it inside your viewDidLoad
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
TotalField.text = [ NSString stringWthFormat: #"%i", (HourlyRateField.text.intValue * NumberOfHoursField.text.intValue) ];
}

ios uiviewcontroller inheritance throws duplicate symbols error

I have a parent view controller with a single method I want available to all child classes:
#import "GAViewController.h"
#interface GAViewController ()<UITextFieldDelegate>
#end
#implementation GAViewController
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
#end
I have a register view controller which looks like this:
//.h
#import <UIKit/UIKit.h>
#import "GAViewController.h"
#import "GAViewController.m"
#interface GARegisterViewController : GAViewController
#end
//.m
#import "GARegisterViewController.h"
#interface GARegisterViewController ()<UIActionSheetDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIGestureRecognizerDelegate>
#property (weak, nonatomic) IBOutlet UIButton *registerButton;
#property (weak, nonatomic) IBOutlet UITextField *userNameTextField;
#property (weak, nonatomic) IBOutlet UITextField *passwordTextField;
#property (weak, nonatomic) IBOutlet UITextField *firstNameTextField;
#property (weak, nonatomic) IBOutlet UITextField *lastNameTextField;
#property (weak, nonatomic) IBOutlet UITextField *phoneNumberTextField;
#property (weak, nonatomic) IBOutlet UISegmentedControl *genderSegmentedContoller;
#end
#implementation GARegisterViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self makeTextFieldDelegates];
}
- (void)makeTextFieldDelegates{
[self.userNameTextField setDelegate:self];
[self.passwordTextField setDelegate:self];
[self.firstNameTextField setDelegate:self];
[self.lastNameTextField setDelegate:self];
[self.phoneNumberTextField setDelegate:self];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
Here is the error I receive:
Does anyone know I can either fix the error above? Or create a parent class correctly with the textFieldShoudlReturn method so that I don't have to include in all my views.
Thanks!
I am importing .m because it contains the textfieldshouldreturn method, it also imports the .h file
It is importing .m file that causes duplicate symbols. Importing a .m file causes the file from which it is imported to define the same symbols (such as method implementations and functions / variables with external scope) as the .m file being included, causing the duplication.
For the same reason one should never place #implementation blocks into header files.
In order to fix this, make a header for GAViewController, and declare textFieldShouldReturn: inside it. Remove #import "GAViewController.m" from your headers and .m files, replacing with #import "GAViewController.h". This should fix the problem.

iOS: implementation of custom UITableViewCell needs to call super

"* Assertion failure in -[PlayingCell layoutSublayersOfLayer:],
/SourceCache/UIKit_Sim/UIKit-2372/UIView.m:5776 2013-11-01
18:44:12.526 SnapTrack[216:c07] * Terminating app due to uncaught
exception 'NSInternalInconsistencyException', reason: 'Auto Layout
still required after executing -layoutSubviews. PlayingCell's
implementation of -layoutSubviews needs to call super.'"
I'm trying to run my app (which I designed for iOS7) in the iOS6 simulator. My project contains a TabBarController. In the first view controller in the tabbarcontroller I have a table view containing custom UITableViewCell's. They load without a problem. However, when I switch to another tab, where I have another table view, also with custom cells, I get the error posted above. The viewControllers are set up almost identically (both have subviews organized with auto layout). Has anyone seen this exception/know how to address it?
Thanks!
EDIT: Code for PlayingCell.
#import <UIKit/UIKit.h>
#interface PlayingCell : UITableViewCell
#property (strong, nonatomic) IBOutlet UILabel *lblTrackNum;
#property (strong, nonatomic) IBOutlet UIImageView *albumArt;
#property (strong, nonatomic) IBOutlet UILabel *lblSongTitle;
#property (strong, nonatomic) IBOutlet UILabel *lblAlbumTitle;
#property (strong, nonatomic) IBOutlet UILabel *lblArtist;
#property (strong, nonatomic) IBOutlet UIImageView *imgPlay;
#property (strong,nonatomic) NSMutableDictionary *songInfo;
- (IBAction)downloadBtnPressed:(id)sender;
#end
#import "PlayingCell.h"
#implementation PlayingCell
#synthesize songInfo;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
- (IBAction)downloadBtnPressed:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[songInfo objectForKey:#"trackViewUrl"]]];
NSLog(#"%#",[songInfo objectForKey:#"trackViewUrl"]);
}
-(void)layoutSubviews
{
[super layoutSubviews];
}
Do what the error states. In one of your custom cell classes you appear to be overriding the layoutSubviews method. You must call [super layoutSubviews] in your implementation. This is typically the 1st line.
- (void)layoutSubviews {
[super layoutSubviews];
// the rest of your custom layout code
}

IB Connections in Xcode crashing

I was working on my iOS app last night when I went to test it and it crashed on startup. I wasn't even working on the nib that is causing the crash. Anyways, here is the error code:
2/29/12 10:32:05.291 AM Safe Flight: *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0xdd496f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Airport1.'
*** First throw call stack:
(0x2873052 0x33add0a 0x2872f11 0x1ae2032 0x1a53f7b 0x1a53eeb 0x1a6ed60 0x136191a 0x2874e1a 0x27de821 0x136046e 0x1362010 0x114214a 0x1142461 0x11417c0 0x1150743 0x11511f8 0x1144aa9 0x37b7fa9 0x28471c5 0x27ac022 0x27aa90a 0x27a9db4 0x27a9ccb 0x11412a7 0x1142a9b 0x3710 0x2f35)
Airport1 is just a label with an IBOutlet correctly connected to it. Also, if I delete the connection the error just is with the next item that has an connection.
Also, my FileOwners class it correctly set to the appropriate viewController.
// MasterViewController.h
#import <UIKit/UIKit.h>
#import "MobclixAds.h"
#class DataViewController;
#class EditViewController;
#class SearchViewController;
#interface MasterViewController : UIViewController{
UILabel *Airport1;
UILabel *Airport2;
UILabel *Airport3;
UILabel *Airport4;
UILabel *Airport5;
UILabel *Airport6;
UILabel *Airport7;
UILabel *Airport8;
UILabel *Airport9;
UIButton *Airport1B;
UIButton *Airport2B;
UIButton *Airport3B;
UIButton *Airport4B;
UIButton *Airport5B;
UIButton *Airport6B;
UIButton *Airport7B;
UIButton *Airport8B;
UIButton *Airport9B;
MobclixAdView* adView;
}
#property (strong, nonatomic) DataViewController *dataViewController;
#property (strong, nonatomic) EditViewController *editViewController;
#property (strong, nonatomic) SearchViewController *searchViewController;
#property (nonatomic, retain) IBOutlet UILabel *Airport1;
#property (nonatomic, retain) IBOutlet UILabel *Airport2;
#property (nonatomic, retain) IBOutlet UILabel *Airport3;
#property (nonatomic, retain) IBOutlet UILabel *Airport4;
#property (nonatomic, retain) IBOutlet UILabel *Airport5;
#property (nonatomic, retain) IBOutlet UILabel *Airport6;
#property (nonatomic, retain) IBOutlet UILabel *Airport7;
#property (nonatomic, retain) IBOutlet UILabel *Airport8;
#property (nonatomic, retain) IBOutlet UILabel *Airport9;
#property (nonatomic, retain) IBOutlet UIButton *Airport1B;
#property (nonatomic, retain) IBOutlet UIButton *Airport2B;
#property (nonatomic, retain) IBOutlet UIButton *Airport3B;
#property (nonatomic, retain) IBOutlet UIButton *Airport4B;
#property (nonatomic, retain) IBOutlet UIButton *Airport5B;
#property (nonatomic, retain) IBOutlet UIButton *Airport6B;
#property (nonatomic, retain) IBOutlet UIButton *Airport7B;
#property (nonatomic, retain) IBOutlet UIButton *Airport8B;
#property (nonatomic, retain) IBOutlet UIButton *Airport9B;
#property(nonatomic,retain) IBOutlet MobclixAdView* adView;
#end
and
// MasterViewController.m
#import "MasterViewController.h"
#import "DataViewController.h"
#import "EditViewController.h"
#import "SearchViewController.h"
#implementation MasterViewController
#synthesize dataViewController = _dataViewController;
#synthesize editViewController = _editViewController;
#synthesize searchViewController = _searchViewController;
#synthesize Airport1, Airport2, Airport3, Airport4, Airport5, Airport6, Airport7, Airport8, Airport9;
#synthesize Airport1B, Airport2B, Airport3B, Airport4B, Airport5B, Airport6B, Airport7B, Airport8B, Airport9B;
#synthesize adView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = #"Safe Flight";
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
}
return self;
}
So is my problem with my code? or with Xcode itself?? I have restarted Xcode and the simulator and even did a "clean" build (it sounded like it would help...)
Thanks,
Andrew
EDIT This is my AppDelegate and I'm setting the correct xib to the window
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Mobclix start];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"MasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
PROBLEM SOLVED!!!
I can't answer my own question because of some stupid spam filter... and I can post a picture of the problem... but its fixed!
but here is a link to the problem click here
Found the Problem!! I feel kinda stupid now ;) but anyways, here is a screenshot of the problem!
The reason causing to crash could be the connection mistakes within xib to header.
Airport1 could be connected to another class than MasterViewController.
If your label connected to File's Owner - it should be MasterViewController.
If you've created another UIViewController within xib and connected Airport1 label to it, then this controller also should be connected to MasterViewController (Identity Inspector "Class" field.)
Updated. Added Screenshots:
When you initialize the MasterViewController (wherever you are launching it from), make sure you are initializing it with the appropriate nib file
Ex.
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:#"YourNibName" bundle:nil];

Add UIButtons to a ScrollView

I'd like to display 5 Buttons in a ScrollView Box but unfortunately the code I wrote has no effects on my UIButtons (I can't Scroll up or Down , can you tell me why ?
Thanks for you help, I spent a lot of hours on it (Rookie) but i still can't find the solution...
My Code :
FirstViewController.h :
#import <UIKit/UIKit.h>
#interface FirstViewController : UIViewController <UIScrollViewDelegate> {
IBOutlet UIScrollView *scroll;
UIButton *button;
UIButton *button2;
UIButton *button3;
}
#property (nonatomic, retain) IBOutlet UIButton *button;
#property (nonatomic, retain) IBOutlet UIButton *button2;
#property (nonatomic, retain) IBOutlet UIButton *button3;
#property(nonatomic,retain) IBOutlet UIScrollView *scroll;
#end
FirstViewController.m :
#import "FirstViewController.h"
#implementation FirstViewController
#synthesize button;
#synthesize button2;
#synthesize button3;
#synthesize scroll;
- (IBAction)goToViewTwo {
}
- (void)viewDidload {
[super viewDidLoad];
[scroll setScrollEnabled:YES];
[scroll setContentSize:CGSizeMake (500, 1000)];
}
- (void)dealloc {
[super dealloc];
[button release];
[scroll release];
}
#end
Hierarchy in FirstView.xib:
View
Action Sheet
Text View
ScrollView
Button
Button
Button
About the Outlets :
Scrollview is linked to File's Owner with "Scroll"
View is linked to File's Owner as a "view"
I suppose you're implementing the scroll in Interface Builder and that the app is for iPad (for the contentSize). See if you have the same configuration in IB and in code, especially that [scroll setScrollEnabled:YES];

Resources