Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
What is the better way to do this (the more buttons the longer the code is getting)?
Does one have to add to an array (then use reflection to look at the variable title and pull out the proper string?
//Load defaults
_n1From = [HelperMethods getObjectUserDefault:AS_N1_FROM_UD];
_n1To = [HelperMethods getObjectUserDefault:AS_N1_TO_UD];
_n2From = [HelperMethods getObjectUserDefault:AS_N2_FROM_UD];
_n2To = [HelperMethods getObjectUserDefault:AS_N2_TO_UD];
_unionRate = [HelperMethods getObjectUserDefault:AS_UNION_RATE_UD];
_unionHours = [HelperMethods getObjectUserDefault:AS_UNION_HOURS_UD];
_nonUnionRate = [HelperMethods getObjectUserDefault:AS_NON_UNION_RATE_UD];
_nonUnionHours = [HelperMethods getObjectUserDefault:AS_NON_UNION_HOURS_UD];
Put buttons into IBOutletCollection, assign each button a unique tag value, and then use the tag to look up the argument in an NSArray that mapps the tag to the parameter. Here is an example:
NSArray *tagToArg = #[#AS_N1_FROM_UD, #AS_N1_TO_UD, #AS_N2_FROM_UD, ...];
for (UIButton *b in allButtonsOutletCollection) {
[HelperMethods configureButton:b withData:tagToArg[b.tag]];
}
The button with the tag zero will get the argument AS_N1_FROM_UD; the button with the tag 1 will get AS_N1_TO_UD, and so on.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
How to use objc_setAssociatedObject to associate with the object?
OBJC_EXPORT void objc_setAssociatedObject(id object, const void *key, id value, objc_AssociationPolicy policy)
The value must be an Objective-C object. You need to wrap the struct in an Objective-C class. You could use NSValue for this.
StructType s = ...;
NSValue* value = [NSValue valueWithBytes:&s objCType:#encode(StructType)];
objc_setAssociatedObject(obj, SPECIAL_KEY, value, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
...
NSValue* value = objc_getAssociatedObject(obj, SPECIAL_KEY);
StructType s;
[value getValue:&s];
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I use below line of code to allocate an Object(Suppose my Object name is Car) dynamically.
[self initliazieObject:[Car class]]
- (id)initliazieObject:(Class)model{
id record = [[model alloc] init];
return record;
}
How I can do this in swift 3.
Exactly as in Objective-C. Try this in a playground:
class Car : NSObject {}
func factory(type:NSObject.Type) -> NSObject {
return type.init()
}
let c = factory(type:Car.self)
print(type(of:c)) // Car
(We can get fancy and do clever things with generics or Self to specify the type of the returned object more precisely, but my goal in this code is simply to do things the dumb way, just like Objective-C.)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want the new number to get a new line without removing the old number ?
See the picture
Try
if let exitingText = label.text
{
label.text = exitingText + "\n" + (textField.text ?? "")
}
and set
label.numberOflines = 0
Here is the code you can use on click of button
- (IBAction)btnAppendTextClicked:(id)sender
{
NSString *oldText=_lblWithText.text;
_lblWithText.text=[NSString stringWithFormat:#"%#\n%#",oldText,_txtValues.text];
_lblWithText.numberOfLines=0;
_lblWithText.preferredMaxLayoutWidth =self.view.frame.size.width;
[_lblWithText setNeedsDisplay];
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I do have two Arrays one array with list of items:
One array with string objects
and one with Array objects
NSArray * a=[1,2,nil];
NSArray * b=[[abc],[def],[ijk],[lmp], nil];
I want to return Array by mapping Array "a" object "1" to array "b" with objects "[abc],[def]"
and Array "a" object "2" to array "b" with objects "[ijk],[lmp]"
I know I can achieve it in NSDictionary but i want to return NSArray not NSDictionary.
or any alternative method to do it.
I think it's more about data structures knowledges?
I see that your pattern is to increase two index.
So, it's something you want?
NSMutableArray *object;
NSUInteger indexOfA = [a indexOfObject:#1]; // get the index of the object from A
for (NSUInteger index = 0; index < 2; index++) {
[object addObject:b[indexOfA * 2 + index]];
}
Then, you can pull out what you want from b.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am trying to put a number from a textfield on a Parse database and I need to specify that it is a number. How can I do this?
I have done the equivalent with a string using .text
Your question is unclear but I think you mean something like this:
UITextField *textField = ... // some text field
int age = [textField.text intValue];
user[#"age"] = #(age);
You need to convert the string value from the UITextField to a number, (e.g. int, double, or NSNumber).
NSString *textInput = myTextField.text;
int intValue = [textInput intValue];
NSNumber *age = [NSNumber numberWithInt:intValue];
user[#"age"] = age;