Updates from Sujith Krishnan RSS Toggle Comment Threads | Keyboard Shortcuts

  • Sujith Krishnan 2:04 pm on May 21, 2011 Permalink | Reply  

    Developing iPhone and iPad Apps that Leverage Windows Azure 

    You are building apps for the iPhone/iPad, yet you remain curious about what the cloud can offer. Is it possible to deploy scalable, mobile Web applications on Windows Azure? How about storing data in the cloud? Is it possible to use the cloud for push notifications to the device? In this session you’ll learn how to integrate iOS applications into an existing Windows Azure infrastructure, and what types of applications other organizations are building. You’ll walk away confident in knowing how to extend your existing applications to take advantage of features on the device together with services in the cloud.

    Click here for video clip

     
  • Sujith Krishnan 11:57 am on December 2, 2010 Permalink | Reply
    Tags: , Compile Sources, copy Bundle Resources, Xcode   

    Excluding file from compilation in Xcode 

    By default, when you create a new file or import a file into Xcode, if the file type is recognized as a source file (.c, .m .js, etc), the file is added to the Compile Sources folder in the application target.
    You may not always prefer this default action – for example, if a JavaScript file is imported, Xcode does not know what to do with this file type so a compile warning is generated

    Read More

     
    • Fadi 1:51 pm on December 29, 2010 Permalink | Reply

      Hello Sujith Krishnan,

      can you please contact me on my email f.naaji@mnmtunes.com if you interested in a job.

      regards,
      Fadi

  • Sujith Krishnan 10:25 am on September 9, 2010 Permalink | Reply
    Tags: NSString to UIImage, text to image, UIImage with NSString   

    Creating an UIImage with given text and size 


    static UIImage *createImageWithText(CGSize imageSize, NSString *text) {

    // Create a bitmap graphics context of the given size
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = CGBitmapContextCreate(NULL, imageSize.width, imageSize.height, 8, imageSize.width*4, colorSpace, kCGImageAlphaPremultipliedLast);
    CGColorSpaceRelease(colorSpace);
    if (context== NULL) {
    return nil;
    }

    // Custom CGContext coordinate system is flipped with respect to UIView, so transform, then push
    CGContextTranslateCTM(context,0,imageSize.height);
    CGContextScaleCTM(context, 1.0, -1.0);
    UIGraphicsPushContext(context);

    // Inset the text rect then draw the text
    CGRect textRect = CGRectMake(4, 2, imageSize.width - 8, imageSize.height - 8);
    UIFont *font = [UIFont boldSystemFontOfSize:24];
    [[UIColor whiteColor] set];
    [text drawInRect:textRect withFont:font
    lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentCenter];

    // Create and return the UIImage object
    CGImageRef cgImage = CGBitmapContextCreateImage(context);
    UIImage *uiImage = [[UIImage alloc] initWithCGImage:cgImage];
    UIGraphicsPopContext();
    CGContextRelease(context);
    CGImageRelease(cgImage);
    return uiImage;
    }

    Note: This is a repost of this

     
  • Sujith Krishnan 3:10 am on March 22, 2009 Permalink | Reply  

    iPhone developement – Beginner’s Tutorials 

    Part 1:  Kickoff iPhone Development
    This presentation tells the environment requirements and basic necessities to start with iPhone App Development.
    Slideshare:

    Part 2: A Closer Look
    This session will give a brief introduction to memory management and a closer look to APIs and components
    Slideshare:

    Part 3: More than UI
    This session deals with the APIs in Foundation framework.
    Slideshare:

     
    • Mark 7:22 pm on May 8, 2009 Permalink | Reply

      what is it? All this information is given on iPhone developer site. Are you capable of writing anything new?

      • Sujith Krishnan 1:37 pm on May 21, 2011 Permalink | Reply

        @Mark

        Yes. all these are available there. This is for a specific set of audience.
        thanks for your suggestion.

    • Vaibhav Tekam 6:17 am on May 11, 2009 Permalink | Reply

      Hi Sujith,
      First of all, let me congratulate u for ur blog. It has been always nice to see someone writing a blog and sharing his knowledge with others. Keep it up.

      I am new to world of iPhone SDK, still a learner. I read ur first tuts. I still did not get the AutoRelease Pool thing. Can u elaborate a little more on it.

      Also I have a question, I have tried few SQLite tuts. I am trying to access a remote server. What I understood thro’ different online forums that, it will be beneficial if I use any php site which will return me data from the remote server which i want to access, in a XML format, then I can parse it using NSXMLParser class and use in my project. is this the right approach?Please let me know.
      Thanks and Regards.
      Vaibhav Tekam

      • Sujith Krishnan 6:58 pm on May 11, 2009 Permalink | Reply

        Hi Vaibhav,
        Thanks for your wishes.

        Also being a newbie, i really welcome you to this interesting world of iPhone App Dev.
        1)First of all i just uploaded some presentations which can serve as just a kick-start / brief intro. So for knowing more in depth about AutoReleasePool and many other interesting APIs, please make use of the documents available at http://developer.apple.com/iphone.
        But i can tell you that autoreleasepool are used in code block where a lot of autoreleased objects are allocating( eg : Factory methods which will allocate an object}. Its just to improve performance, minimizing memory footprints and leaks etc…

        However detached threads must have AutoreleasePool for the entire code block. (Recommended)

        2)Yeah…
        Almost all the projects i deal with iPhone are making use of xml communication with server which i found pretty easy with NSXMLParser.

        If you want to deal with saving any data to device (persist) i think Archiving/Unarchiving is also a good option. The headache with developer in this case is to design the right data structure / classes for application data. But again very simple when compared to dealing with SQLite.

        Enjoy learning Vaibhav.
        Do posing your queries. I will try my level best.

  • Sujith Krishnan 6:00 am on March 17, 2009 Permalink | Reply  

    Horizontal UIPickerView 

    A situation can arise when you want to have some horizontal UIPickerView in your application.

    Something like what in the picture shown below

    horizontal_pickerview

    Following code will draw one like that..

    -(void)loadView:{
    // Write code to create self.view
    // Then...
    pickerViewArray = [[NSArray arrayWithObjects:
     @"John Appleseed", @"Chris Armstrong", @"Serena Auroux",
     @"Susan Bean", @"Luis Becerra", @"Kate Bell", @"Alain Briere",
     nil] retain];
     myPickerView = [[UIPickerView alloc] initWithFrame:CGRectZero];
     myPickerView.delegate = self;
     myPickerView.showsSelectionIndicator =YES;
     myPickerView.backgroundColor = [UIColor clearColor];
     CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14/2);
     rotate = CGAffineTransformScale(rotate, 0.25, 2.0);
     [self.myPickerView setTransform:rotate];
     [self.view addSubview:myPickerView];
    } 
    
    // UIPickerViewDelegate
    
    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    	CGRect rect = CGRectMake(0, 0, 120, 80);
    	UILabel *label = [[UILabel alloc]initWithFrame:rect];
    	CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14/2);
    	rotate = CGAffineTransformScale(rotate, 0.25, 2.0);
    	[label setTransform:rotate];
    	label.text = [pickerViewArray objectAtIndex:row];
    	label.font = [UIFont systemFontOfSize:22.0];
    	label.textAlignment = UITextAlignmentCenter;
    	label.numberOfLines = 2;
    	label.lineBreakMode = UILineBreakModeWordWrap;
    	label.backgroundColor = [UIColor clearColor];
    	label.clipsToBounds = YES;
    	return label ;
    }
    

    Courtesy: Syed Yusuf

     
    • pramod 8:22 am on July 24, 2009 Permalink | Reply

      I would like to know , Do Appstore will have any objection for the app to be submitted if we modify the standard controls size or the way it was supposed to be used as per IPHONE HIG(Human interface guidelines)

    • Sujith Krishnan 8:34 am on July 24, 2009 Permalink | Reply

      I don’t think there is such kind of objection from Apple ( however i am not ruling out that).
      I have tried customizing the alertviews/actionsheets (in shape, color etc..) and successfully uploaded to app store.

      I think Apple don’t stand against your creativity/ideas :) :)
      However its not advisable to use undocumented APIs, even though you can run the app without any error/warning. They will reject such apps.

      Happy Coding . . . .

    • nebyate 3:25 pm on November 15, 2009 Permalink | Reply

      while creating my Horizontal picker

      I got a problem with:
      [self.picker setTransform:rotate];

      error:

      accessing unknown ‘picker’ getter method

      • Sujith Krishnan 6:31 am on November 16, 2009 Permalink | Reply

        @nebyate

        Please check your property declaration. Check your @synthesize part as well.

    • Charlie 2:10 am on December 22, 2009 Permalink | Reply

      Where do I find the UIPickerViewDelegate? I do not know how to lay out the example. Do you have a full working example available?

      thanks

      • Sujith Krishnan 5:30 am on December 22, 2009 Permalink | Reply

        Just type ‘ UIPickerViewDelegate’ and ‘Jump to definition’ .
        You can find the delegate methods there.
        Please make it clear what you are trying to achieve so that i can help you better. Dont forget to set pickerInstance.delegate = self :)

    • Jay 7:39 pm on December 22, 2009 Permalink | Reply

      thanks for the tip!

      One thing I ran into when I tried this technique was that all my picker views were displayed upside down. On line 23 where the rotation of the label is computed, I’m pretty sure it should be :

      CGAffineTransform rotate = CGAffineTransformMakeRotation(-3.14/2); // note the negative sign

      this would rotate the label 90 degrees counter-clockwise relative to the rotation applied to the PickerView.

    • livia 4:37 pm on January 24, 2010 Permalink | Reply

      I get the names written upside down …
      what am I doing wrong ?

    • Chris 7:42 pm on January 25, 2010 Permalink | Reply

      Hi,

      i added a dataSource to to get it working:

      #pragma UIPickerViewDataSource

      • (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {

      return 1;
      }

      • (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {

      return [pickerViewArray count];
      }

      and in loadview:

      myPickerView.dataSource = self;

      What i can’t figure out is how to make the picker smaller in height (or width before the rotation) initializing with a different frame only affects the y offset. Like to put it on the top of the screen i do:

      myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, -68, 0, 0)];

      any ideas?

      regards

      Chris

    • Lukassen 10:35 pm on January 31, 2010 Permalink | Reply

      Brilliant, I’ve been looking for a way to do this for quite some time.
      I suppose if you want a picker less heigh one could transform with .5 and invert the transform on the label but I haven’t figured out that yet

    • Vilem 4:14 pm on June 3, 2010 Permalink | Reply

      I am quite new to iphone programming so I suppose this is stupid question, but please answer anyway, I am just learning everything :)

      I can not get values on picker – something is wrong with the delegate, or delegate assingment. But I do not understand – the delegate method wants back UIView class, and you return UILabel? Is that right?

    • Ganesh Krishnan 10:56 pm on August 7, 2010 Permalink | Reply

      I am not able to get the same in a UITableViewCell. It just refuses to show if I add it as a subview. Can you point what I may be missing?

    • Seraphin Hochart 11:05 pm on August 13, 2010 Permalink | Reply

      I think that’s :
      CGAffineTransform rotate = CGAffineTransformMakeRotation(-3.14/2);

      So with a -3.14 on line 23 only (It was upside/down with the code just copied and pasted!

      Great anyway, thanks!

    • Husyn 4:21 pm on October 16, 2010 Permalink | Reply

      Thnx for this tutorial. I’m having some problems plz help me. I copy pasted loadView code in my viewDidLoad method. Created UIPickerView *myPickerView; and NSArray *pickerViewArray in my .h file. There is no compilation error but text is not shown on picker. can you help me plz… :)

    • saurabh 9:28 pm on December 1, 2010 Permalink | Reply

      *setTransform:rotate];* does the trick .. simple and effective! nice thanks!!

    • faisal 1:22 pm on January 4, 2011 Permalink | Reply

      Thanks, this is very helpful, I have a problem I would appreciate if you can help, I used the above code but the text is upside down?? I tried changing all the angels no help, any idea??

    • faisal 1:43 pm on January 4, 2011 Permalink | Reply

      I sorted it out, it should be :( 3.14/2)+3.14)

    • Narayanan 11:13 am on May 16, 2011 Permalink | Reply

      It appears inverted to me :(
      I am using the code as it is

      • Sujith Krishnan 1:54 pm on May 21, 2011 Permalink | Reply

        @Narayanan

        Please see above comments. A few people already came up with the solution.

    • marco 8:33 am on June 21, 2011 Permalink | Reply

      can you send me the source code of the final working one?? I am confused

      • Sujith Krishnan 9:24 am on June 21, 2011 Permalink | Reply

        @macro
        The code is only that much. loadView and the delegate are enough.
        You want to write numberofRows delegate methods as well.

        I dont have the full code right now, and i did this years before.

      • rita 12:13 am on July 1, 2011 Permalink | Reply

        Thanks for this great code. Very useful. I am copying the full source code for .h and .m files of View Controller below. I used a View-Based app template of Xcode 4 to start with.

        #import

        @interface MyHorizontalPickerViewViewController : UIViewController {

        NSArray *pickerViewArray;
        UIPickerView *myPickerView;
        }

        @property (nonatomic, retain) IBOutlet UIPickerView *myPickerView;

        @end

        #import “MyHorizontalPickerViewViewController.h”

        @implementation MyHorizontalPickerViewViewController
        @synthesize myPickerView;

        -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)myPickerView {
        return 1;
        }

        -(NSInteger)pickerView:(UIPickerView *)myPickerView numberOfRowsInComponent:(NSInteger)component {
        return [pickerViewArray count];
        }

        • (void)dealloc

        {
        [myPickerView release];
        [super dealloc];
        }

        • (void)didReceiveMemoryWarning

        {
        [super didReceiveMemoryWarning];
        }

        • (void)viewDidLoad

        {
        pickerViewArray = [[NSArray arrayWithObjects:
        @"John Appleseed", @"Chris Armstrong", @"Serena Auroux",
        @"Susan Bean", @"Luis Becerra", @"Kate Bell", @"Alain Briere",
        nil] retain];
        myPickerView = [[UIPickerView alloc] initWithFrame:CGRectZero];
        myPickerView.delegate = self;
        myPickerView.showsSelectionIndicator =YES;
        myPickerView.backgroundColor = [UIColor clearColor];
        CGAffineTransform rotate = CGAffineTransformMakeRotation(-3.14/2);
        rotate = CGAffineTransformScale(rotate, 0.25, 2.0);
        [self.myPickerView setTransform:rotate];
        [self.view addSubview:myPickerView];
        [super viewDidLoad];
        }

        • (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{

        CGRect rect = CGRectMake(0, 0, 120, 80);
        UILabel *label = [[UILabel alloc]initWithFrame:rect];
        CGAffineTransform rotate = CGAffineTransformMakeRotation(3.14/2);
        rotate = CGAffineTransformScale(rotate, 0.25, 2.0);
        [label setTransform:rotate];
        label.text = [pickerViewArray objectAtIndex:row];
        label.font = [UIFont systemFontOfSize:22.0];
        label.textAlignment = UITextAlignmentCenter;
        label.numberOfLines = 2;
        label.lineBreakMode = UILineBreakModeWordWrap;
        label.backgroundColor = [UIColor clearColor];
        label.clipsToBounds = YES;
        return label ;
        }

        • (void)viewDidUnload

        {
        [myPickerView release];
        myPickerView = nil;
        [self setMyPickerView:nil];
        [super viewDidUnload];
        }

        @end

    • mike 6:03 am on November 14, 2011 Permalink | Reply

      i am not able to position the picker view correctly. it somehow appears at the center of the screen while i want it to be on the top of the view.

      • Sujith Krishnan 6:54 am on November 14, 2011 Permalink | Reply

        @mike
        You can override the position of the view at any point.
        Play with the setFrame: method to position the pickerView wherever you want.
        Note that there is a combination of rotation/scaling transform for the pickerview.

  • Sujith Krishnan 10:24 am on March 3, 2009 Permalink | Reply
    Tags: email, email syntax, , NSPredicate, validation   

    Email syntax validation -iPhone Programming 

    Understanding that iPhone SDK dont support NSPredicate which is there for MAC Apps SDK i wrote an Utility Method to do a syntax validation of email.

    -(BOOL)validateEmail:(NSString*)email
    
    if( (0 != [email rangeOfString:@"@"].length) &&  (0 != [email rangeOfString:@"."].length) )
    	{
    		NSMutableCharacterSet *invalidCharSet = [[[[NSCharacterSet alphanumericCharacterSet] invertedSet]mutableCopy]autorelease];
    		[invalidCharSet removeCharactersInString:@"_-"];
    
    		NSRange range1 = [email rangeOfString:@"@" options:NSCaseInsensitiveSearch];
    
    		// If username part contains any character other than "."  "_" "-"
    
    		NSString *usernamePart = [email substringToIndex:range1.location];
    		NSArray *stringsArray1 = [usernamePart componentsSeparatedByString:@"."];
    		for (NSString *string in stringsArray1) {
    			NSRange rangeOfInavlidChars=[string rangeOfCharacterFromSet: invalidCharSet];
    			if(rangeOfInavlidChars.length !=0 || [string isEqualToString:@""])
    				return NO;
    		}
    
    		NSString *domainPart = [email substringFromIndex:range1.location+1];
    		NSArray *stringsArray2 = [domainPart componentsSeparatedByString:@"."];
    
    		for (NSString *string in stringsArray2) {
    			NSRange rangeOfInavlidChars=[string rangeOfCharacterFromSet:invalidCharSet];
    			if(rangeOfInavlidChars.length !=0 || [string isEqualToString:@""])
    				return NO;
    		}
    
    		return YES;
    	}
    	else // no '@' or '.' present
    		return NO;
    
    

     
    • Sujith Krishnan 6:11 pm on March 23, 2009 Permalink | Reply

      Hi all,

      This is an update.
      The iPhone SDK 3.0 (beta) is having NSPredicate API…
      The job is now simplified..
      No need to write your custom email syntax validator.
      Now we can use the regular expression…

      Still i love my validator method… :)

    • Jathin 9:52 am on August 12, 2010 Permalink | Reply

      Loved your code. I love it much more than the NSPredicate API…Good job…

    • dileep 11:26 am on December 8, 2010 Permalink | Reply

      hi sukri..
      great validator… it did help alot…

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

      will return add.add@..com as a valid one..
      but urs works great..

      • Sujith Krishnan 1:49 pm on May 21, 2011 Permalink | Reply

        @dileep

        well.. the Predicate validator is again by some developer and not by apple i believe.

        happy to know that you are preferring my code over the most popular. :)

  • Sujith Krishnan 5:46 am on February 12, 2009 Permalink | Reply  

    Our App in ‘Staff Favorite’ List 

     

    Our App in Staff Favorite List

    Our App in Staff Favorite List

    Today we got a mail from the client that one of the app we created is listed in the “Staff Favorite” List…and appearing in the ‘Home page’ of App Store… its cool…

    Moreover all our apps are listed in first page for ‘Valentine Special’ list as well.. Cheers…

     
  • Sujith Krishnan 11:12 am on February 6, 2009 Permalink | Reply
    Tags: tilt iPhone, UIAccelerometer, UIAccelerometerDelegate   

    UIAccelerometer 

    I started incorporating the accelerometer events in my app.
    My app is quite similar to the
    SampleDrillDown (one of the example app provided by apple). I am having menus in my app, which are like
    Category -> Sub category -> final item page

    All the above navigations are through pushing view controllers.

    I am trying to add accelerometer delegate methods to select any of the cell in tableview on tilting the device up or down, moreover tilting right will push the view controller and tilting left will pop.

    • My concern is about how to set delegate for UIAccelerometer for such an implementation? 
    • Also the method like “selectCellAtIndexPath” will simply highlight the cell, so i want to call UITableView’s delegate method  ”didSelectRowAtIndexPath” explicitly. ( to push corresponding viewcontroller)

    I don’t think there is much harm in doing so..
    But i would like to hear from someone who implemented this in much better way…

    Checkout an abstract sample code

     
  • Sujith Krishnan 5:52 am on February 6, 2009 Permalink | Reply
    Tags: c, , conditional compilation, , ipod, objective c   

    Conditional compilation – easy way !! 

    I achieved this by adding a #define in .pch file for each project.

    and do #import based on that definition using #ifdef

    This is the pretty cool and easy way  if your are sharing single source code set across multiple target/build/project

    Just make use of different .pch file for different builds.

    You want to create <n>  number of .pch file for <n> targets. Assign corresponding  .pch file for each target’s info


     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel
Follow

Get every new post delivered to your Inbox.