- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIDevice currentDevice]setOrientation:UIInterfaceOrientationPortrait];
// Add the tab bar controller’s view to the window and display.
[window addSubview:tabBarController.view];
//Take this line this line and put it in your code.
tabBarController.selectedIndex = 2;
[window makeKeyAndVisible];
return YES;
}
Archive for the ‘iPhone’ Category
You’ll have to implement a URL scheme. For example, if one app’s URL scheme is appone://, then you can launch app one from app two like this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"appone://"]];
Create a separate instance of NSMUtablearray each time you populate and insert it, otherwise you keep re-using the same instance, so only the last state of it appears in each position of the array.
NSMutableArray *myArray = [NSMutableArray array];
for (int i = 0 ; i != 10 ; i++) {
NSMutableDictionary *m = [NSMutableDictionary dictionary];
// Presumably, this part is done differently on each iteration
[m setObject:a forKey:@"a"];
[m setObject:b forKey:@"b"];
[m setObject:c forKey:@"c"];
[m setObject:d forKey:@"d"];
[myArray addObject:m];
}
-(BOOL)ccScrollWheel:(NSEvent*)theEvent {
CGFloat deltaX = [theEvent deltaX], deltaY = [theEvent deltaY], deltaZ = [theEvent deltaZ];
sample_sprite.position = ccp( sample_sprite.position.x, sample_sprite.position.y+deltaY*5);//moving a sprite vertically by scrolling the scrollwheel
return TRUE;
}
NSAlert *alertView = [NSAlert alertWithMessageText:@"title" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:@"message"]; [alertView runModal];
We will need to implement the touch/drag events directly.
Check out the touchesBegan, touchesMoved etc. delegate methods in UIResponder.
One approach would be to subclass imageview and implement touchesBegan, touchesMoved in it, and use this imageview subclass to display our images in the scroll view.
On the touchesBegan create a new image view and add it to the outer view and set its image to be the same as the one in the scroll view. We need to overlay it directly over our source image in the scroll view so adjust its frame origin to be relative to the outer view we will need to use the scrollview origin and also the content view size and offset of the source image view inside the content view in order to recalculate the new origin in the outer view.
Then on the touches moved, simply readjust the frame of this image in accordance with the coordinates from the touches moved so that the image follows the touch.
Do a boundary check against the frame of our target imageview – once the user drags it into this boundary, make that target imageviews image the same as the image in the view being dragged and remove the dragged image from the containing view and release it.
In Cocos2D Android, positioning elements is a very tedious process. In most cases, the absolute position that we give will not be used as it is. You can fix this issue by setting the following properties of that element :
Consider a CCSprite object, mySprite. Now you have to set the following properties of that object before positioning it absolutely
mySprite.setAnchorPoint(0, 0); mySprite.setRelativeAnchorPoint(true);
Now if you give the absolute position for the object, it will work fine.
The following method will return the array with items in reverse order. The input given to this method is the NSMutableArray, the contents of which you want to reverse and the output will the NSMutableArray with the values reversed.
- (NSMutableArray *)reverseArray:(NSMutableArray *)arraytoReverse {
if ([arraytoReverse count] == 0)
return arraytoReverse; // Return from the method if the array is empty.
NSUInteger start = 0; // Setting the initial counter.
NSUInteger end = [arraytoReverse count] - 1; // Setting the final counter.
while (start < end) { // Iterating through the contents of the array.
[arraytoReverse exchangeObjectAtIndex: start withObjectAtIndex: end];
start ++;
end--;
}
return arraytoReverse; // Returning the array with values reversed.
}
For getting available font styles for a particular font in iPhone app,
NSLog(@"%@", [UIFont fontNamesForFamilyName:@"Helvetica Neue"]);
It prints all available font styles for Helvetica Neue, among them , one is HelveticaNeue-Medium
For checking whether plist does exist,
if ([[NSFileManager defaultManager] fileExistsAtPath:plistPath] == 0) {
//Plist Exists
}
For checking it doesn’t exist,
if ([[NSFileManager defaultManager] fileExistsAtPath:plistPath] != 0) {
//Plist didn't exist
}
since the code returns 0 when the file does exist.




