You can do it as follows:
|
1 2 |
NSString* str = @"teststring"; NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding]; |
let us make technology work for you
You can do it as follows:
|
1 2 |
NSString* str = @"teststring"; NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding]; |
In .h file:
|
1 |
@interface myViewController : UIViewController<UIPickerViewDelegate> |
In .m file:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
UIPickerView *myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 200)]; myPickerView.delegate = self; myPickerView.showsSelectionIndicator = YES; [self.view addSubview:myPickerView]; - (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component { // Handle the selection } // tell the picker how many rows are available for a given component - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { NSUInteger numRows = 5; return numRows; } // tell the picker how many components it will have - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1; } // tell the picker the title for a given component - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { NSString *title; title = [@"" stringByAppendingFormat:@"%d",row]; return title; } // tell the picker the width of each row for a given component - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component { int sectionWidth = 300; return sectionWidth; } |
You can create an UISegmented control in a cocos2d or Xcode project with the help of following lines code:
// Create an UIView
|
1 2 3 4 |
UIView *profileView = [[UIView alloc] init]; profileView.frame = CGRectMake(0, 50, 320, 395); profileView.backgroundColor = [UIColor clearColor]; [[[CCDirector sharedDirector] openGLView] addSubview:profileView]; |
// Create the segmented control label array
|
1 |
NSArray *itemArray = [NSArray arrayWithObjects: @"Credit", @"Debit", nil]; |
// Create the UISegmentedControl and add to the UIView
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray]; segmentedControl.frame = CGRectMake(5, 20, 150, 35); segmentedControl.center = CGPointMake(220, (50*5)); segmentedControl.segmentedControlStyle = UISegmentedControlStylePlain; segmentedControl.selectedSegmentIndex = 1; segmentedControl.tintColor = [UIColor colorWithRed:0.1f green:0.4f blue:0.65f alpha:1.0f]; segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; [segmentedControl addTarget:self action:@selector(segmentChanged:) forControlEvents:UIControlEventValueChanged]; [profileView addSubview:segmentedControl]; |
You can create an UIswitch in cocos2d or Xcode programatically with the help of following lines of code:
// Create an UIView
|
1 2 3 4 |
UIView *profileView = [[UIView alloc] init]; profileView.frame = CGRectMake(0, 50, 320, 395); profileView.backgroundColor = [UIColor clearColor]; [[[CCDirector sharedDirector] openGLView] addSubview:profileView]; |
// Create the switch and add to the UIView
|
1 2 3 4 5 |
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame: CGRectMake(130, 235, 0, 0)]; [mySwitch addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged]; [profileView addSubview:mySwitch]; |
// Call function to get state
|
1 2 3 |
-(void)changeSwitch:(UISwitch *)mySwitch{ NSLog(@"%@", mySwitch.on ? @"On" : @"Off"); } |
The common undefined symbol error appearing while integrating test flight will be something like the following :
Undefined symbols for architecture armv7s:
“_deflateInit_”, referenced from:
_compress_data in libTestFlight.a(tf_compression.o)
“_deflateEnd”, referenced from:
_compress_data in libTestFlight.a(tf_compression.o)
“_deflate”, referenced from:
_compress_data in libTestFlight.a(tf_compression.o)
ld: symbol(s) not found for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The fix for this issue is simple.
Goto the build phases of the target for which the issue is appearing. In the link binary with libraries section, use the ‘+’ button at the bottom to add a new library. In the dialog box which appears, search for libz.dylib . You will see the library in the list. Select that and press the ‘Add’ button.
Now perform a build clean for the project and you are done.
Build the app and the issue will be fixed.
You can change/disable the highlight color of a table cell using the following codes…
|
1 2 3 |
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue]; // set highlighting color = Blue [cell setSelectionStyle:UITableViewCellSelectionStyleGray]; // set highlighting color = Gray [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; // Disable highlighting |
We can get the child view controllers of a view controller using the childViewControllers property of the view controller.
If we are in a view controller class, if we want to get its child view controllers, then we can use the following code :
self.childViewControllers;
This will return an array of view controllers that are the child of the current view controller.
If there are no child view controllers of the current view controller, then the array will be empty.
If we are to get the child view controllers of a navigation controller, we can use the following code :
self.navigationController.childViewControllers;
It is possible to pass a single parameter to performSelector: method in Xcode using the following method :
[self performSelector:@selector(selectorNamewithArg:) withObject:param];
But what to do if we have to pass multiple parameters? There is a way to pass upto two parameters to the performSelector: method. It can be implemented using the following method :
[self performSelector:@selector(selectorNamewithArg1: Arg2:) withObject:param1 withObject:param2];
Here, two parameters are passed to the selector method.
You have to use a CCSpeed action:
CCSpeed* speed= [CCSpeed actionWithAction: yourMoveAction speed: 1.0f];
// yourMoveAction is an action like CCMoveTo for example
[sprite runAction: speed];
Then you can change the speed while the sprite moves with setSpeed:
[speed setSpeed: 2.0f];
First Assign the string to an id:
|
1 2 3 |
for (int j=1; j<=15; j++) id GameScene = NSClassFromString([NSString stringWithFormat:@"GamePage_%d",j]); } |
Then call the scene transition with that id:
|
1 |
[[CCDirector sharedDirector] replaceScene:[GameScene scene]]; |