I am trying to upload assignments into a table in an different view controller. First when i click on the upload button this code runs.
- (IBAction)uploadAssignment:(id)sender {
nameOfAssignmentAsString = self.nameOfAssignment.text;
NSLog(#"%#", nameOfAssignmentAsString);
NSInteger row;
row = [self.subjectPicker selectedRowInComponent:0];
subjectOfAssignmentAsString = [subjectArray objectAtIndex:row];
NSLog(#"%#", subjectOfAssignmentAsString);
NSDate *deadline = [self.deadlinePicker date];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:#"dd/MM/yyyy"];
deadlineOfAssignmentAsString = [dateFormat stringFromDate:deadline];
NSLog(#"%#",deadlineOfAssignmentAsString);
HomeworkViewController *HVC;
[HVC.nameOfAssignmentInAnArray addObject:nameOfAssignmentAsString];
[HVC.SubjectOfAssignmentInAnArray addObject:subjectOfAssignmentAsString];
[HVC.deadlineOfAssignmentInAnArray addObject:deadlineOfAssignmentAsString];
NSLog(#"%#",HVC.nameOfAssignmentInAnArray.count);
}
then in my HomeworkViewController.h this is the code
#interface HomeworkViewController : UIViewController <UIGestureRecognizerDelegate,UITableViewDataSource,UITableViewDelegate> {
int i;
}
#property (strong, nonatomic) IBOutlet UIView *mainMenu;
#property (strong, nonatomic) IBOutlet UIButton *homeworkButton;
#property (strong, nonatomic) IBOutlet UIButton *uploadButton;
#property (strong, nonatomic) NSMutableArray *nameOfAssignmentInAnArray;
#property (strong, nonatomic) NSMutableArray *SubjectOfAssignmentInAnArray;
#property (strong, nonatomic) NSMutableArray *deadlineOfAssignmentInAnArray;
I did initialise it in my HomeworkViewController.m file. But for some reason the string is not being added into the array.
You declare HVC but never assign a value to it. Therefore it cannot hold anything in itself. But for some reason the designers of Objective-C decided it's not an error to send messages to nil objects, so this might not be noticed.
Related
I wonder if there is anything wrong in this code:
//MyViewController.h
#interface MyViewController : UIViewController
#property (weak, nonatomic) IBOutlet UILabel *aLabel;
#property (strong, nonatomic) NSString *myString;
#end
//MyViewController.m
#implementation MyViewController
-(void)setMyString:(NSString *)myString{
if (_myString != myString) {
_myString = myString;
self.myLabel.text = myString;
}
}
#end
Regards!
you need
![_myString isEqualToString: myString];
instead of
_myString != myString
PS:
also use
self->_myString
please make sure that you are using
self.myString = #"new String"
instead of
_myString = #"new String"
self.property is equal to [self setProperty]
I have mutable array of class like :
#protocol CategoryModel #end
#interface CategoryModel : NSObject
#property (assign) int Id;
#property (strong, nonatomic) NSString* ShortString;
#property (strong, nonatomic) NSString* Description;
#property (strong, nonatomic) NSString* AppId;
#end
I want to get an Nsdata of the AppId , how to do that
and I want to search this NsMutableArry by Id
As far as I understand you want to get data from array by Id. You can use NSPredicate for this:
[myArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"Id == %d", yourID]];
Good Morning Guys,
I have a problem. I have an application that do a calculate. If i insert the Label in a same ViewController i watch all.
How do I insert the same Label in another View?
This is the view where there is the calculate.
H.
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet UITextField *textField1;
#property (strong, nonatomic) IBOutlet UITextField *textField2;
#property (strong, nonatomic) IBOutlet UIButton *result;
#property (strong, nonatomic) IBOutlet UIDatePicker *data;
#end
M.
//
// ViewController.m
// IEcigarette
//
// Created by Federico on 24/11/12.
// Copyright (c) 2012 Federico. All rights reserved.
//
#import "ViewController.h"
#import "ResultViewController.h"
#interface ViewController ()
#property (strong, nonatomic) NSString * myString;
#property (strong, nonatomic) UILabel * myLabel;
#end
#implementation ViewController
-(IBAction)calculate:(id)sender{
NSDate *past = _data.date ;
NSDate *now = [NSDate date];
NSCalendar *gregorianCalendar = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger unitFlags = NSDayCalendarUnit;
NSDateComponents *components = [gregorianCalendar components:unitFlags
fromDate:past
toDate:now
options:0];
int z = [components day];
int a = ([_textField1.text intValue]);
int b = a*([_textField2.text intValue]);
int r = b * z / 20;
_myLabel.text = [[NSString alloc] initWithFormat:#"%d", r];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (BOOL)textFieldShouldReturn:(UILabel *)myLabel {
[myLabel resignFirstResponder];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
[self performSegueWithIdentifier:#"detail" sender:self];
}
return YES;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"detail"]) {
ResultViewController* destVC = (ResultViewController*)segue.destinationViewController;
destVC.myString = self.myLabel.text;
destVC.navigationItem.title = self.myLabel.text;
}
}
#end
Thank you
why you are trying to insert the same label to the another view also. just pass the label.text (string) to another view controller's string. then use that string and create a new label with this string in the viewdidload method . you can also pass the value using nsuserdefaults.
You could keep a reference to it in a shared and call:
[yourLabel removeFromSuperview];
[yourViewController.view addSubview:yourLabel];
for every view controller you want to display it on.
However if what you're sharing is pretty much functioning as a UILabel, I would recommend using separate UILabel instances for each view controller and just sharing the .text value across views. You could pass the value in prepareForSegue, save it to NSUserDefaults, set it as a property of some shared object/singleton.
I have a uipickerview which i want to populate with data from my sqlite database.
I have got access to the data via a mutable array via the appdelegate but when i use that as the data source it is crashing the app when used as the uipicker titleforrow section.
The count from the array is correct it just will not display any data!
Here is my header file:
#class OBMessage;
#interface LocationViewController : UIViewController <UITableViewDelegate, UIPickerViewDelegate, UIPickerViewDataSource, UITableViewDataSource, UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate> {
UITableViewCell *cell1;
UITableViewCell *cell2;
UITableViewCell *cell3;
UITableViewCell *cell4;
UITableViewCell *cell5;
UITableViewCell *cell6;
UITableViewCell *cell7;
UITableViewCell *cell8;
IBOutlet UILabel *addressLabel;
MKPlacemark *placemark;
IBOutlet UILabel *lLat;
IBOutlet UILabel *lLong;
IBOutlet UILabel *lHAcc;
IBOutlet UILabel *lAlt;
IBOutlet UILabel *lVAcc;
IBOutlet UILabel *lDate;
UIPickerView *singlePicker;
NSArray *pickerData;
NSString *pickedInfo;
DadsTaxiV2AppDelegate *appDelegate;
NSMutableArray *myarray;
}
#property (nonatomic, retain) IBOutlet UITableViewCell *cell1;
#property (nonatomic, retain) IBOutlet UITableViewCell *cell2;
#property (nonatomic, retain) IBOutlet UITableViewCell *cell3;
#property (nonatomic, retain) IBOutlet UITableViewCell *cell4;
#property (nonatomic, retain) IBOutlet UITableViewCell *cell5;
#property (nonatomic, retain) IBOutlet UITableViewCell *cell6;
#property (nonatomic, retain) IBOutlet UITableViewCell *cell7;
#property (nonatomic, retain) IBOutlet UITableViewCell *cell8;
#property (nonatomic, retain) IBOutlet UILabel *addressLabel;
#property (nonatomic, retain) IBOutlet UILabel *lLat;
#property (nonatomic, retain) IBOutlet UILabel *lLong;
#property (nonatomic, retain) IBOutlet UILabel *lHAcc;
#property (nonatomic, retain) IBOutlet UILabel *lAlt;
#property (nonatomic, retain) IBOutlet UILabel *lVAcc;
#property (nonatomic, retain) IBOutlet UILabel *lDate;
#property (nonatomic, retain) IBOutlet UIPickerView *singlePicker;
#property (nonatomic, retain) NSArray *pickerData;
#property (nonatomic, retain) NSString *pickedInfo;
#property (nonatomic, retain) NSMutableArray *myarray;
#property (nonatomic, retain) MKPlacemark *placemark;
-(IBAction)popupCameraSheet:(id)sender;
-(IBAction)popupMessageSheet:(id)sender;
-(void)showPicker;
#end
Here is bits of my m file:
- (void)viewDidLoad {
[super viewDidLoad];
appDelegate = (DadsTaxiV2AppDelegate *)[[UIApplication sharedApplication] delegate];
self.myarray = appDelegate.messageArray;
}
-(void)showPicker
{
UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:#"Select a Office Buddy Message to Include:"
delegate:self
cancelButtonTitle:#"Select" destructiveButtonTitle:#"Cancel"
otherButtonTitles:nil];
menu.tag = 4;
menu.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
singlePicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 185, 0, 0)];
singlePicker.delegate=self;
singlePicker.showsSelectionIndicator = YES;
[singlePicker selectedRowInComponent:0];
[singlePicker reloadComponent:0];
[menu addSubview:singlePicker];
[menu showInView:self.view];
[menu setBounds:CGRectMake(0, 0, 320, 700)];
[singlePicker release];
[menu release];
//NSInteger row = [singlePicker selectedRowInComponent:1];
//NSString *selected = [pickerData objectAtIndex:row];
//infoLabel.text = selected;
}
#pragma mark Picker Data Source Methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
//NSLog(#"[pickerData count]=%d",[pickerData count]);
//return [pickerData count];
NSLog(#"[messagearray count]=%d",[self.myarray count]);
//return [self.pickerData count];
return [self.myarray count];
}
#pragma mark Picker Delegate Methods
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSLog(#"[pickerData objectAtIndex:row]=%#",[self.myarray objectAtIndex:row]);
//return [self.pickerData objectAtIndex:row];
return [self.myarray objectAtIndex:row];
}
Sorry forgot the crash log:
didSelectViewController:<LocationViewController: 0x9b7de90>
2012-09-07 20:43:07.142 OfficeBuddy[7300:c07] [messagearray count]=13
2012-09-07 20:43:07.142 OfficeBuddy[7300:c07] [messagearray count]=13
2012-09-07 20:43:07.142 OfficeBuddy[7300:c07] [pickerData objectAtIndex:row]=<OBMessage: 0x9a74ae0>
2012-09-07 20:43:07.143 OfficeBuddy[7300:c07] -[OBMessage isEqualToString:]: unrecognized selector sent to instance 0x9a74ae0
2012-09-07 20:43:07.144 OfficeBuddy[7300:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[OBMessage isEqualToString:]: unrecognized selector sent to instance 0x9a74ae0'
*** First throw call stack:
(0x1759022 0x1a5ecd6 0x175acbd 0x16bfed0 0x16bfcb2 0x8ed0ff 0xbcf17a 0x7a8bc0 0x847c54 0x8483ce 0x833cbd 0x83271a 0x83c220 0xbcf6bb 0x7a77ec 0x7a84f9 0x8ca1 0xcc71 0x83e5c5 0x83e7fa 0x47585d 0x172d936 0x172d3d7 0x1690790 0x168fd84 0x168fc9b 0x22847d8 0x228488a 0x7ad626 0x2f5d 0x2ed5)
terminate called throwing an exception(lldb)
By your crash log, it seems that the data you are populating your array with is an instance of the OBMessage class. When returning from the datasource method:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
Make sure you are returning a string. So, if your array is populated by instances of the OBMessage, use a property from that class that represents what you want to present on your picker. For example, if OBMessage has a property called messageStringRepresentation, you would return:
return [[self.myarray objectAtIndex:row] messageStringRepresentation];
Try to print the array objects and confirm NSString objects. or post a code if you have used isEqualToString somewhere in your code.
My app keeps coming up with a "Semantic Error" and keeps freezing/crashing.Everything seems to be stringed together fine and it launches without problem. TextFields work fine but as soon as I click anything else it fails and forces out. Any recommendations?
h.
#interface ViewController : UIViewController {
IBOutlet UITextField *buy1;
IBOutlet UITextField *sell1;
IBOutlet UILabel *percentage1;
IBOutlet UILabel *profit1;
IBOutlet UITextField *royalty;
IBOutlet UITextField *buy2;
IBOutlet UILabel *sell2;
IBOutlet UITextField *percentage2;
IBOutlet UILabel *profit2;
}
#property (weak, nonatomic) IBOutlet UITextField *buytext1;
#property (weak, nonatomic) IBOutlet UITextField *selltext1;
#property (weak, nonatomic) IBOutlet UILabel *percentage1;
#property (weak, nonatomic) IBOutlet UILabel *profit1;
#property (weak, nonatomic) IBOutlet UITextField *royalty;
#property (weak, nonatomic) IBOutlet UITextField *buytext2;
#property (weak, nonatomic) IBOutlet UILabel *sell2;
#property (weak, nonatomic) IBOutlet UITextField *percentagetext2;
#property (weak, nonatomic) IBOutlet UILabel *profit2;
-(IBAction)Button;
- (IBAction)backgroundTouched:(id)sender;
- (IBAction)textfieldReturn:(id)sender;
#end
m.
#implementation ViewController
//This is where I keep getting the Semantic Error "Incomplete Implementation"
#synthesize buytext1;
#synthesize selltext1;
#synthesize buytext2;
#synthesize percentagetext2;
- (IBAction)backgroundTouched:(id)sender {
[buy1 resignFirstResponder];
[sell1 resignFirstResponder];
[buy2 resignFirstResponder];
[percentage2 resignFirstResponder];
}
- (IBAction)textFieldReturn:(id)sender {
[buy1 resignFirstResponder];
[sell1 resignFirstResponder];
[buy2 resignFirstResponder];
[percentage2 resignFirstResponder];
}
int VarBuy1 = 0;
int VarSell1 = 0;
int VarProfit1 =0;
int VarPercentage1 =0;
int VarRoyalty = 0;
int VarBuy2 = 0;
int VarSell2 = 0;
int VarProfit2 =0;
int VarPercentage2 =0;
-(IBAction)Button{
VarBuy1 = ([buy1.text intValue]);
VarSell1 = ([sell1.text intValue]);
VarProfit1 = (VarSell1 - (VarSell1 * (VarRoyalty / 100)) - VarBuy1);
VarPercentage1 = (VarProfit1 / VarSell1);
VarSell2 = (VarBuy2 / ((100 - VarRoyalty) / 100 - VarPercentage2));
VarProfit2 = (VarSell2 - (VarSell2 * VarRoyalty) - VarBuy2);
profit1.text = [[NSNumber numberWithInt:VarProfit1] stringValue];
percentage1.text = [[NSNumber numberWithInt:VarPercentage1] stringValue];
sell2.text = [[NSNumber numberWithInt:VarSell2] stringValue];
profit2.text = [[NSNumber numberWithInt:VarProfit2] stringValue];
}
#end
In .h
- (IBAction)textfieldReturn:(id)sender;
In .m
- (IBAction)textFieldReturn:(id)sender
Be careful about letter cases. field and Field.
And an IBAction without (id)sender doesn't sound good.