Archive for the ‘Objective C’ Category

05
Apr

Consider a UITableView object, myTableView.

// To make the background of the tableview transparent, use the following code :
myTableView.backgroundColor = [UIColor clearColor];

(or)

[myTableView setBackgroundColor:[UIColor clearColor]];
// The above code will make the color of the tableview's background transparent.

 

//Now sometimes, this code will not do the trick. In such cases, what you have to do is use the following line of code along with the above code.
myTableView.backgroundView = nil;

(or)

[myTableView setBackgroundView:nil];
// The above code will make the background view to nil.

, ,

30
Mar
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: @"http://myurl/mypic.jpg"]]; cell.image = [UIImage imageWithData: imageData]; [imageData release];

30
Mar

Just include the following method in your cocos2D class file and it will be called when ever that class/scene gets loaded.

- (void) onEnterTransitionDidFinish{

NSLog(@"- (void) onEnterTransitionDidFinish ");

}

, ,

27
Mar

It is not possible to add a UIImageView directly as a subView to UIWebView. So if you want to add a UIImageView object as a subview to UIWebView, use the following code.

Consider a UIWebVIew object myWebView, to which you want to add a UIImageView object, myImageView.

Now you can add myImageView to myWebView as follows :

[[[myWebView subviews] objectAtIndex:0] addSubview:myImageView];
// This will do the trick.

In this code, we are adding the UIImageView object to the subview of the UIWebView, which is a UIScrollView.

, , ,

26
Mar
TableViewCategory *detailViewController = [[TableViewCategory alloc] initWithNibName:@"TableViewCategory" bundle:nil];

    detailViewController.delegate = self;

//Allocing and initializing popover with table view controller.
    popover = [[UIPopoverController alloc]
                                    initWithContentViewController:detailViewController];

    popover.popoverContentSize = CGSizeMake(300, 300);
    popover.delegate = self;
    [detailViewController release];

    [popover presentPopoverFromRect:CGRectMake(440, 350, 1, 1)
                             inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp
                           animated:YES];

25
Mar
+(BOOL)isOS4{
	NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"4.0" options: NSNumericSearch];
	if (order == NSOrderedSame || order == NSOrderedDescending) {
		return YES;
	} else {
		return NO;
	}
}

25
Mar
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{
	switch (result) {
		case MessageComposeResultCancelled:
			NSLog(@"Cancelled");
			break;
		case MessageComposeResultFailed:{
			UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Application" message:@"Unknown Error"
														   delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
			[alert show];
			[alert release];
			break;}
		case MessageComposeResultSent:

			break;
		default:
			break;
	}

	[self dismissModalViewControllerAnimated:YES];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

	//SMS
	if(buttonIndex == 0){
		MFMessageComposeViewController *controller = [[[MFMessageComposeViewController alloc] init] autorelease];
		if([MFMessageComposeViewController canSendText])
		{
			controller.body = @"SMS Body";
			controller.messageComposeDelegate = self;
			controller.delegate = self;
			[self presentModalViewController:controller animated:YES];
		} else {
		}
	}

}

23
Mar
int main (int argc, char * argv[])

{

NSAutoreleasePool * pool = [[NSAutoreleasePool alloc]init];

//Define the variables .

double thisNum;

char thisChar;

BOOL isFinished;

PrintCalc * CalcInstant = [[PrintCalc alloc]init];

//Initialize the isFinished variable.

isFinished = false;

//The do-while loop should terminate with the falsification of the isFinished boolean.

do

{

    scanf (" %f %c", &thisNum, &thisChar);

    //Use a 'switch' statement to make multiple decisions and meet multiple conditions.

    switch (thisChar)

    {

        case 'S':

            [CalcInstant setAccumulator: thisNum];

            NSLog(@"= %f", [CalcInstant accumulator]);

            break;

        case '+':

            [CalcInstant add: thisNum];

            NSLog(@"= %f", [CalcInstant accumulator]);

            break;

        case '-':

            [CalcInstant subtract: thisNum];

            NSLog(@"= %f", [CalcInstant accumulator]);

            break;

        case '*':

            [CalcInstant multiply: thisNum];

            NSLog(@"= %f", [CalcInstant accumulator]);

            break;

        case '/':

            [CalcInstant divide: thisNum];

            NSLog(@"= %f", [CalcInstant accumulator]);

            break;

        case 'E':

            isFinished = true;

            break;

        //This next case is a 'hidden' operator that only the programmer knows about. Displays the value of the thisNum variable.

        case '@':

            NSLog(@">>> %f", thisNum);

            break;

        default:

            NSLog(@"Bad operator and/or not a real number.");

            break;

    }

}

while (isFinished != true);

NSLog(@"= %g", [CalcInstant accumulator]);

[CalcInstant release];

[pool drain];

return 0;

}

20
Mar
- (BOOL) validateEmail: (NSString *) emailVal {

    NSString *emailregex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailregex];
    return [emailTest evaluateWithObject:emailVal];
}

you can make a function call like this.

[self validateEmail:@"xyz@example.com"];

19
Mar

Consider two points startPoint and endPoint.

Now you can find the angle between these two points as follows :

float angleVal = (((atan2((endPoint.x – startPoint.x) , (endPoint.y – startPoint.y)))*180)/M_PI); // Here angleVal will have the angle between the two points.

Example :

Consider the following points :

CGPoint endPoint = CGPointMake(50, 100);

CGPoint startPoint = CGPointMake(100, 100);

float angleVal = (((atan2((endPoint.x - startPoint.x) , (endPoint.y - startPoint.y)))*180)/M_PI);

NSLog(@"Angle %.0f", angleVal); // This will give the result as -90, the angle between the two points that I gave as input.

, ,