My view controller contains an UIImageView and a UITextView below. This is my code:
#import <UIKit/UIKit.h>
#interface DescriptionViewController : UIViewController
#property (nonatomic, strong) IBOutlet UIImageView *descriptionImage;
#property (nonatomic, strong) IBOutlet UITextView *descriptionText;
#property (nonatomic, strong) NSString *text;
#property (nonatomic, strong) NSString *image;
#end
#interface DescriptionViewController ()
#end
#implementation DescriptionViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.descriptionText = [[UITextView alloc] init];
self.descriptionImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.image]]];
self.descriptionText.text = self.text;
NSLog(#"%#", self.descriptionText.text);
}
#end
My code doesn't show up in textview, but I can print it using NSLog.
What could be the problem ?
You're initializing a new UITextView here.-
self.descriptionText = [[UITextView alloc] init];
This way, you get a new UITextView not linked with the main view. Remove that line and make sure descriptionText is properly linked in your xib or storyboard.
However, if your intention was actually programmatically creating a new UITextView from scratch, then you'll also have to programmatically add it to your main view.
Related
I am trying to get my UITextField email in my first view controller to become the UILabel in my next view controller. It says there is an error stating there is no visible #interface for NSString declares the selector initvalue. I thought the interface was being loaded from the vc1.h file when you imported it on the vc2? any help would be nice. Heres what I have so far:
vc1.h
#import <UIKit/UIKit.h>
#interface loginUserViewController : UIViewController
#property (nonatomic, retain, strong) IBOutlet UITextField *email;
#property (nonatomic, retain) IBOutlet UITextField *password;
#property (nonatomic, retain) IBOutlet UIButton *login;
#property (nonatomic,retain) IBOutlet UIButton *registerBtn;
-(IBAction)loginUser:(id)sender;
#end
vc2.h
#import <UIKit/UIKit.h>
#import "loginUserViewController.h"
#interface Home : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *username;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *Nav;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *logout;
-(IBAction)logout:(id)sender;
-(IBAction)bandHome:(id)sender;
#end
vc2.m
import "Home.h"
#import "loginUserViewController.h"
#interface Home ()
#end
#implementation Home
#synthesize username, band1, band2, band3;
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self){
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
loginUserViewController *object = [[loginUserViewController alloc]init];
NSString *string = [[NSString alloc] initWithFormat:#"%i",[object.email.text initValue]];
username.text = string;
}
vc1.m
#import "loginUserViewController.h"
#import "Home.h"
#import "createBandViewController.h"
#interface loginUserViewController ()
#end
#implementation loginUserViewController
#synthesize email, password;
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
}
- (void)viewDidload
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[self setEmail:nil];
[self setPassword:nil];
[super viewDidUnload];
}
-(IBAction)loginUser:(id)sender {
if ([email.text isEqualToString:#""] || [password.text isEqualToString:#""])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"alert" message:#"Please Fill all the field" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return;
}
Simply replace this string:
NSString *string = [[NSString alloc] initWithFormat:#"%i",[object.email.text initValue]];
with this string:
NSString *string = [[NSString alloc] initWithFormat:#"%i",[object.email.text intValue]];
and if you want simply the email just as a string then replace it with this string
NSString *string = [[NSString alloc] initWithFormat:#"%#",object.email.text];
your error will be resolved.Hope it helps :)
First of All in VC2.h
#import <UIKit/UIKit.h>
#import "loginUserViewController.h"
#interface Home : UIViewController
#property (strong, nonatomic) IBOutlet UILabel *username; // Keep property strong to get the value
in VC2.m
#synthesize username;
Now in VC1.h
#import <UIKit/UIKit.h>
#import "homeviewcontroller.h"
#interface loginUserViewController : UIViewController
#property (nonatomic, strong) IBOutlet UITextField *email;
#property (nonatomic, strong) IBOutlet UITextField *password;
#property (nonatomic) nsstring *username;
-(void)viewDidLoad
{
[super viewDidLoad];
username= self.email.text;
homeviewcontroller *object = [[homeviewcontroller alloc]init];
object.username.text=username;
}
I know it was trivial but I have messed myself up and spent hours.
I have a UIViewController which is composed of CategoryTableview and ProductsTableView.
The ProductsTableView is creating the customized TableViewCell called ProductTableViewCell.
The ProductTableViewCell has title label, detail label, price label and a customized stepper to control the amount of the products which is subclassing from UIViewController.
The stepper, is composed with two buttons and a textfield.
I think the way I'm implementing the program is more complex than it should be.
And my question is how to detect the value changed by the stepper controller in the parent view controller.
The code is:
ProductionViewController.h (parent view controller for listing everything)
#interface ProductionViewController ()<UITableViewDataSource, UITableViewDelegate>
#property (nonatomic,strong) UITableView* categoryTable;
#property (nonatomic,strong) UITableView* productsTable;
#property (nonatomic,strong) CheckOutBar* checkOutBar;
//datasources
#property (nonatomic,strong) NSMutableArray* menuLists;
#property (nonatomic,strong) NSMutableArray* detailLists;
//datefield
#property (nonatomic,strong) NSString* startDate;
#property (nonatomic,strong) NSString* endDate;
the customized cell for products is
#interface ProductCell : UITableViewCell
#property (nonatomic, strong) UIImageView* eqiupmentImage;
#property (nonatomic, strong) UILabel* Title;
#property (nonatomic, strong) UILabel* details;
#property (nonatomic, strong) UILabel* prices;
#property (nonatomic, strong) MCStepperViewController* stepper;
The implementing method of the cell is
#implementation ProductCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
{
_Title = [[UILabel alloc] init];
_eqiupmentImage = [[UIImageView alloc] init];
_details = [[UILabel alloc] init];
_details.font = kFONT(12);
_details.textColor = KColor_Gray;
_prices = [[UILabel alloc] init];
_stepper = [[MCStepperViewController alloc] init];
[self.contentView addSubview:_stepper.view];
[self.contentView addSubview:_Title];
[self.contentView addSubview:_eqiupmentImage];
[self.contentView addSubview:_details];
[self.contentView addSubview:_prices];
}
return self;
}
-(void)layoutSubviews
{
[super layoutSubviews];
[_eqiupmentImage setFrame:CGRectMake(kLeftMargin, kLeftMargin, 80 ,80)];
[_Title setFrame:CGRectMake(10+CGRectGetMaxX(_eqiupmentImage.frame), kLeftMargin/2, 60, 20)];
[_details setFrame:CGRectOffset(_Title.frame, 0, 20)];
[_prices setFrame:CGRectMake(10+CGRectGetMaxX(_eqiupmentImage.frame), CGRectGetMaxY(_eqiupmentImage.frame)-20, 40, 20)];
[_stepper.view setFrame:CGRectOffset(_prices.frame, 40, 0)];
}
The customized stepperview is
MCStepperViewController.h (for controlling the amount of products)
#interface MCStepperViewController : UIViewController
#property (nonatomic, strong) UITextField *amountText;
#property (nonatomic, strong) UIButton * plusButton;
#property (nonatomic, strong) UIButton * minusButton;
#property (nonatomic, assign) int max;
#property (nonatomic, assign) int min;
#property (nonatomic, assign) int amount;
Thank you
One way could be implementing a protocol in your cells with a method like - (void)productCell:(ProductCell *)cell didChangeStepperValue:(NSInteger)stepperValue. Then you make your view controller a delegate of each cell and call this method every time the stepper changes it's value. To separate cells from each other you could assign their tag value to your model's corresponding index.
Another way is to use KVO, but you should be careful with subscribing/unsubscribing. And using blocks, of course, is a viable option.
I have an app that captures the users signature, myviewcontroller displays the signature capture. I'm attempting to create a rectangle in the center of the screen that is centered for this to happen using CGRect. When I run this I get no errors, but I get the picture below and I can't figure out what is causing this.
Within the CGRect code, I am trying to have the rectangle that is created be centered in the middle of the screen, and the target device is ipad. I've posted both the .h and .m files, the .m file is incomplete as the rest has to do with the code used to capture the signature then save it.
Any help would be appreciated.
//MyViewController.h
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import <Foundation/Foundation.h>
#interface MyViewController : UIViewController <UIAlertViewDelegate>
#property (nonatomic, strong) UIImageView *mySignatureImage;
#property (nonatomic, assign) CGPoint lastContactPoint1, lastContactPoint2, currentPoint;
#property (nonatomic, assign) CGRect imageFrame;
#property (nonatomic, assign) BOOL fingerMoved;
#property (nonatomic, assign) float navbarHeight;
#property (nonatomic, assign) UIImageView* imageView;
#property (nonatomic, retain) NSData*image;
#property (strong, nonatomic) NSManagedObjectContext *managedObjectContext;
//Save and cancel buttons
- (IBAction)cancel:(id)sender;
- (IBAction)save:(id)sender;
#end
//MyViewController.m
#import "MyViewController.h"
#interface MyViewController ()
#end
#implementation MyViewController
#synthesize mySignatureImage;
#synthesize lastContactPoint1, lastContactPoint2, currentPoint;
#synthesize imageFrame;
#synthesize fingerMoved;
#synthesize navbarHeight;
#synthesize image;
#synthesize imageView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor lightGrayColor];
CGRect imageFrame = CGRectMake(
CGRectGetMidX(self.view.frame) - CGRectGetMidX(imageView.frame),
CGRectGetMidY(self.view.frame) - CGRectGetMidY(imageView.frame),
CGRectGetWidth(imageView.frame),
CGRectGetHeight(imageView.frame));
// //allocate an image view and add to the main view
mySignatureImage = [[UIImageView alloc] initWithImage:nil];
mySignatureImage.frame = imageFrame;
mySignatureImage.backgroundColor = [UIColor whiteColor];
[self.view addSubview:mySignatureImage];
}
Move the code (except for [super viewDidLoad]) in viewDidLoad to a later stage, such as viewWillAppear. During viewDidLoad the layout of the views is not yet complete so their bounds/frames are not yet set to their final values.
Try to replace this line:
mySignatureImage = [[UIImageView alloc] initWithImage:nil];
with:
mySignatureImage = [[UIImageView alloc] init];
I have the following app that I've implemented a scroll view (image outlines hierarchy on storyboard:e
I have turned off Auto Layout, as severe posts here seem to indicate this creates a problem.
here is my .h file:
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <AssetsLibrary/ALAsset.h>
#import <AssetsLibrary/ALAssetRepresentation.h>
#import <ImageIO/CGImageSource.h>
#import <ImageIO/CGImageProperties.h>
#import <CoreLocation/CoreLocation.h>
#interface DobInAHoonViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate, MFMailComposeViewControllerDelegate, UITextFieldDelegate, CLLocationManagerDelegate>
{
IBOutlet UIPickerView *vehiclePickerView;
UIImagePickerController *picker1;
UIImagePickerController *picker2;
UIImage *image;
IBOutlet UIImageView *imageView;
CLLocationManager *locationManager;
CGFloat animatedDistance;
}
#property (strong, nonatomic) IBOutlet UIImageView *BackgroundImage;
#property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
#property (strong, nonatomic) NSString *Latitude;
#property (strong, nonatomic) NSString *longditute;
#property (strong, nonatomic) NSArray *toRecipients;
#property (strong, nonatomic) ALAssetsLibrary *assetsLibrary;
#property (strong, nonatomic) NSMutableArray *groups;
#property (nonatomic, retain) IBOutlet UITextField *vehilceMake;
#property (nonatomic, retain) IBOutlet UITextField *vehilceColour;
#property (nonatomic, retain) IBOutlet UITextField *regoNumber;
#property (nonatomic, retain) IBOutlet UITextField *location;
#property (nonatomic, retain) IBOutlet UITextField *additionalInfo;
#property (nonatomic, retain) IBOutlet UITextField *vehicleType;
- (IBAction)takePhoto;
-(IBAction)chooseExisting;
-(IBAction)actionEmailComposer;
-(IBAction)textFileReturn:(id)sender;
-(IBAction)DismissKeyboard:(id)sender;
#end
and my .m file:
#import "DobInAHoonViewController.h"
#interface DobInAHoonViewController ()
#end
#implementation DobInAHoonViewController
#synthesize BackgroundImage;
#synthesize vehilceColour;
#synthesize vehilceMake;
#synthesize regoNumber;
#synthesize Latitude;
#synthesize location;
#synthesize longditute;
#synthesize additionalInfo;
#synthesize toRecipients;
#synthesize assetsLibrary;
#synthesize groups;
#synthesize vehicleType;
#synthesize scrollView;
static const CGFloat KEYBOARD_ANIMATION_DURATION = 0.3;
static const CGFloat MINIMUM_SCROLL_FRACTION = 0.2;
static const CGFloat MAXIMUM_SCROLLFRACTION = 0.8;
static const CGFloat PORTRAIT_KEYBOARD_HEIGHT = 216;
static const CGFloat LANDSCAPE_KEYBOARD_HEIGHT = 140;
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
[vehilceMake resignFirstResponder];
[vehilceMake resignFirstResponder];
[vehilceColour resignFirstResponder];
[location resignFirstResponder];
[additionalInfo resignFirstResponder];
[regoNumber resignFirstResponder];
return YES;
}
- (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.
[self.scrollView setScrollEnabled:YES];
[self.scrollView setContentSize:(CGSizeMake(320, 1000))];
locationManager = [[CLLocationManager alloc]init];
toRecipients = [[NSArray alloc]initWithObjects:#"scott.boon#shellharbour.nsw.gov.au", nil];
BackgroundImage.alpha = 0.3;
static int emergAlertCounter;
if (emergAlertCounter <1) {
UIAlertView *emergencyAlert = [[UIAlertView alloc]
initWithTitle:#"NOTE" message:#"Do not endanger your life to dob in a hoon. If your life is threatened, or you are reporting an emergency situation, exit this app and dial '000' IMMEDIATLY!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[emergencyAlert show];
emergAlertCounter = emergAlertCounter+1;
}
}
for some reason, when i run the app, the scroll view is not scrolling. I have set the property to scroll in the interface builder.
Any suggestions would be greatly appreciated.
You'll have to make sure your scroll view is smaller than 320 x 1000 and that the embedded view is larger than 320 x 1000
I have a created a custom cell and added one label and Image, I have 4 rows in my table each row has a different image and each row opens a different view controller, so, now what I need is on click of a particular row I want the image to change to do that I tried this, but its not working, so please help me out.
if(indexPath.row == 0)
{
if(cell.selected == true)
{
UIImage *cellImage = [UIImage imageNamed:#"abc.png"];
cell.icon.image = cellImage;
}
else
{
UIImage *cellImage = [UIImage imageNamed:#"abc.png"];
cell.icon.image = cellImage;
}
}
Regards
Ranjit
Try to do following when creating your cell or in tableView:willDisplayCell:forRowAtIndexPath: method:
cell.imageView.image = [UIImage imageNamed:#"abc.png"];
cell.imageView.highlightedImage = [UIImage imageNamed:#"abc.png"];
It will work for your icon property too if it is UIImageView
First create a property in your custom cell for uiImageview and synthesize it..
and the in didSelectRowAtIndexPath delegate method of UITabeView access the property and change the image something like :-
yourCell.yourImageView.image=[UIImage imageNamed:#"yourImage"]
For Sample I am giving my Code :-
#import <UIKit/UIKit.h>
#interface CustomizedCellProductDetails : UITableViewCell {
UILabel *sNO;
UILabel *abcWine;
UILabel *redWine;
UILabel *two;
UILabel *hundred;
UILabel *fourTwo;
UILabel *twoOne;
UIImageView *imgView;
UILabel *itemNo;
UILabel *itemName;
UILabel *itemDesc;
UILabel *department;
UILabel *qtyAvailable;
UIButton *check;
}
#property (nonatomic , retain) UILabel *sNO;
#property (nonatomic , retain) UILabel *abcWine;
#property (nonatomic , retain) UILabel *redWine;
#property (nonatomic , retain) UILabel *two;
#property (nonatomic , retain) UILabel *hundred;
#property (nonatomic , retain) UILabel *fourTwo;
#property (nonatomic , retain) UILabel *twoOne;
#property (nonatomic , retain) UIImageView *imgView;
#property (nonatomic , retain) UILabel *itemNo;
#property (nonatomic , retain) UILabel *itemName;
#property (nonatomic , retain) UILabel *itemDesc;
#property (nonatomic , retain) UILabel *department;
#property (nonatomic , retain) UILabel *qtyAvailable;
#property (nonatomic , retain) UIButton *check;
-(void) clicked;
#end
.m file synthesize it:-
#import "CustomizedCellProductDetails.h"
#implementation CustomizedCellProductDetails
#synthesize sNO,abcWine,redWine,two,hundred,fourTwo,twoOne,imgView,itemNo,itemName,itemDesc,department,qtyAvailable,check;
in tableview delegate :-
#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
/*
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:#"<#Nib name#>" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
*/
CustomizedCellProductDetails * cell = (CustomizedCellProductDetails )[tableView cellForRowAtIndexPath:indexPath];
[cell.imgView setImage:[UIImage imageNamed:#"wine.png"]];
}
Try to do following when creating your cell ...
In Implementation Block...
#implementation ABC
{
NSMutableArray *imageArray;
NSMutableArray *imageSelectedArray;
}
Do this In the below method
(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell.imageView setImage:[UIImage imageNamed:[imageArray objectAtIndex:indexPath.row]]];
[cell.imageView setHighlightedImage:[UIImage imageNamed:[imageSelectedArray objectAtIndex:indexPath.row]]];
}