Monday 23 April 2012

Custom Cell in UITableView



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellTableIdentifier = @"CellTableIdentifier";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
    
    
    if (cell == nil) {
        CGRect cellFrame = CGRectMake(0,0,300,65);
        cell = [[[UITableViewCell alloc] initWithFrame: cellFrame
                                       reuseIdentifier:CellTableIdentifier] autorelease];
    
             
        CGRect projectValueRect = CGRectMake(12,44,100,17);
      
        UILabel *projectValue = [[UILabel alloc] initWithFrame:projectValueRect];    
         projectValue.textAlignment = UITextAlignmentLeft;
        projectValue.backgroundColor=[UIColor clearColor];
        projectValue.textColor=[UIColor whiteColor];
       // projectValue.font = [UIFont boldSystemFontOfSize:12];
        projectValue.tag = kProjectValueTag;
        [cell.contentView addSubview:projectValue];
        [projectValue release];

        CGRect RTRect = CGRectMake(90,45,60,15);
        UILabel *RTRectLbl = [[UILabel alloc] initWithFrame:RTRect];           
        RTRectLbl.textAlignment = UITextAlignmentLeft;
        RTRectLbl.text = @"R.Time:";
        RTRectLbl.backgroundColor=[UIColor clearColor];
        RTRectLbl.textColor=[UIColor whiteColor];
        //RTRectLbl.font = [UIFont boldSystemFontOfSize:14];
        [cell.contentView addSubview: RTRectLbl];
        [RTRectLbl release];   

        CGRect timeValueRect = CGRectMake(150,45,60,15);
        UILabel *timeValue = [[UILabel alloc] initWithFrame:timeValueRect];      
        timeValue.backgroundColor=[UIColor clearColor];
        timeValue.textColor=[UIColor whiteColor];
         timeValue.tag = kTimeValueTag;
        [cell.contentView addSubview:timeValue];
        [timeValue release];
        
        CGRect nameValueRect = CGRectMake(10,9,100,15);
        UILabel *nameValue = [[UILabel alloc] initWithFrame:nameValueRect];    
        nameValue.backgroundColor=[UIColor clearColor];
        nameValue.textColor=[UIColor whiteColor];
        nameValue.tag = kNameValueTag;
        [cell.contentView addSubview:nameValue];
        [nameValue release];
        
        CGRect DueDate = CGRectMake(160,9,150,15);
        UILabel *dueDate = [[UILabel alloc] initWithFrame:DueDate];   
        dueDate.backgroundColor=[UIColor clearColor];
        dueDate.textColor=[UIColor whiteColor];
        dueDate.tag = kDueValueTag;
        [cell.contentView addSubview:dueDate];
        [dueDate release];
        
        
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self 
                   action:@selector(cellClick:)
         forControlEvents:UIControlEventTouchDown];
         button.tag=indexPath.row;
         [button setBackgroundImage:[UIImage imageNamed:@"detail.png"] forState:UIControlStateNormal];
        //[button setTitle:@">>" forState:UIControlStateNormal];
        button.frame = CGRectMake(260, 45.0, 45.0, 45.0);
        [cell.contentView addSubview:button];
        
        
        
        
        
    }
    
    // Set up the cell...
    NSLog(@"%d",indexPath.row);
    Tasks *taskDetails=[allTasks objectAtIndex:indexPath.row];
    Projects *projrctDetails=[allProjects objectAtIndex:indexPath.row];
    
    NSLog(@"%@",projrctDetails.project_title);
    
    
    UILabel *name = (UILabel *)[cell.contentView viewWithTag:kNameValueTag];
    name.text = taskDetails.task_title;
    
    UILabel *Duedate = (UILabel *)[cell.contentView viewWithTag:kDueValueTag];
    Duedate.text = taskDetails.task_due_date;
    
    
    UILabel *projectText = (UILabel *)[cell.contentView viewWithTag:kProjectValueTag];
    projectText.text = projrctDetails.project_title;
   
    
    UILabel *timeTag = (UILabel *)[cell.contentView viewWithTag:kTimeValueTag];
   NSTimeInterval lastDiff = [[self.dateFormatter dateFromString:taskDetails.task_due_date] timeIntervalSinceNow];
    
    NSDate *now = [NSDate date];  
    NSString *dateString = [self.dateFormatter stringFromDate:now];
    NSTimeInterval todaysDiff = [[self.dateFormatter dateFromString:dateString] timeIntervalSinceNow];
    NSTimeInterval dateDiff = lastDiff - todaysDiff;
    
    
    div_t h = div(dateDiff, 3600);
    int hours = h.quot;
    // Divide the remainder by 60; the quotient is minutes, the remainder
    // is seconds.
    div_t m = div(h.rem, 60);
    int minutes = m.quot;
    timeTag.text = [NSString stringWithFormat:@" %d:%d",hours,minutes];
    
   // [cell setBackgroundColor:[UIColor colorWithRed:3/255.0f green:130/255.0f blue:242/255.0f alpha:1.0]];
    
    return cell;
}

How to convert NSTimeInterval to hours, minutes


 NSDate *now = [NSDate date];  
    NSString *dateString = [self.dateFormatter stringFromDate:now];
    NSTimeInterval todaysDiff = [[self.dateFormatter dateFromString:dateString] timeIntervalSinceNow];
    NSTimeInterval dateDiff = lastDiff - todaysDiff;
    
    
    div_t h = div(dateDiff, 3600);
    int hours = h.quot;
    // Divide the remainder by 60; the quotient is minutes, the remainder
    // is seconds.
    div_t m = div(h.rem, 60);
    int minutes = m.quot;
    timeTag.text = [NSString stringWithFormat:@" %d:%d",hours,minutes];

Wednesday 18 April 2012

Add current location on map in IOS


-(void)viewWillAppear:(BOOL)animated{
    map.mapType = MKMapTypeStandard;
    map.showsUserLocation=YES;
     NSLog(@"%f%f",self.lat_task,self.long_task);
    CLLocationCoordinate2D coord = {.latitude = self.lat_task, .longitude = self.long_task};
    MKCoordinateSpan span = {.latitudeDelta0.3, .longitudeDelta0.3};
    MKCoordinateRegion region = {coord, span};
    [map setRegion:region];
    //map.delegate=self;
     MKPlacemark *mPlacemark = [[[MKPlacemark alloc] initWithCoordinate:coord    addressDictionary:nil] autorelease];
    [map addAnnotation:mPlacemark];
  

}

Thursday 12 April 2012

8 Things Instagram Did Right


With its billion-dollar sale to Facebook, Instagram instantly became the latest poster child for startup success. In just 551 days, the photo-sharing mobile app zoomed from zero to 30 million-odd users, and 10 million U.S. visits by March 2012, up 1000% since December 2011. Its valuation outstrips that of the 116-year-old New York Times.
An amazing run, and it wasn't all just luck, though the company enjoyed plenty of that. To boost its chances to win the startup lottery, Instagram did eight very important things right.

1. Instagram Operated as a Nimble Start-up

Despite its meteoric growth, Instagram kept its overhead low with a total of only 13 employees, and its headquarters weren't anything to brag about, either. Instagram is housed in Twitter's old digs on 164 South Park Street in the trendy but still slightly seedy SOMA neighborhood of San Francisco.
More important, it stayed nimble enough to switch gears from its original idea of a location-based social network called Burbn to an iPhone app focused solely on photo-sharing. And instead of hiring workers or looking for revenue, the company was able to focus on growing the platform, its community and its aesthetic offerings.

2. Instagram Cashed in on the Mobile Explosion

Instagram's timing was perfect, capitalizing on a historic increase in smartphone use. Starting out as an iOS app, it successfully targeted the burgeoning legions of hip iPhone-app users. It waited until Android reached nearly 50% mobile marketshare to launch the long-awaited app on that platform. Meanwhile, Instagram mostly ignored the no-longer-as-hot Web space, although there is a Web version called Webstagram.

3. Instagram's Interface Stayed Junk-Free

Spend 20 minutes on Instagram and chances are you'll be hooked. Beautiful pictures filtered through hazy lenses flow down an otherwise cold, glass screen. Instagram charges up a smartphone screen, filling it with emotion - not piles of distracting controls and icons. On Instagram, the image stands alone. Instagram successfully created a new world where images - not functionality - are the main focus.

4. Instagram Didn't Get Creepy

Instagram managed to keep its creep vibe low. It doesn't push users to post, to share or even to like - it is an open space, available to use as you wish. Stay on the sidelines and just observe - no one will ever know. Pop into a conversation and then quickly leave. You won't be the only one: Instagram users are notoriously fickle.
That's why Instagram's easy follow/unfollow option doesn't require a commitment as heavy-handed as "friending" on Facebook. Follow whomever you want, or just wander off and find new images to look at. You won't accidentally see some old fling pop up in the Instagram stream, unless you purposely follow that person.

5. Instagram Married Visceral, Visual Communication & Community

Instagram built a devout community based on a single idea: capturing and sharing beautiful images. Powerful images are inherently emotional - think about The Atlantic's In Focus section.
Instagram gave people an easy way to connect around images, without the added pressure of complex social relations. Communities popped up organically around filters, around using too many filters and around just friends.
"There are a lot of things in [a] photo that someone can respond to, [that] promote conversation - then you get a wonderful interaction out of it," says Piictu Community Manager Zachary McCune. "I hope that continues, because that's what's beautiful about being able to relate to photographs."
A talented photographer can capture a single emotion in a square image, and make the viewer stop and feel something, if only for a moment. Instagram makes that moment easier to share.

6. Instagram Created a Valuable New Data Set

Every time an Instagram user snaps a picture, the app can capture a rich set of data, including location, time of day and other data points that can be associated with a smartphone's sensors, explains ReadWriteWeb's Dan Rowinski in How Instagram Will Help Facebook Monetize Mobile.
Instagram may not have been monetizing that data, but you can bet Facebook will. "Facebook is adding another crucial set of data points/edges to analyze people's activity online," says PixableCEO Inaki Berenguer. "With Instagram in the fold, Facebook can now quantify what people are taking photos about based on the tags they put on their photos."

7. Instagram Didn't Worry About Making Money

In its short 15-month lifespan, Instagram focused on building its community, user base and functionality rather than worrying about how the platform was going to make money. By not chasing the dollar, it was able to focus on making the app better.
Of course, Instagram did pay attention to acquiring VC funding. Right before the Facebook acquisition, it closed a $50M Series B round from Sequoia, Thrive, Greylock and Benchmark, valuing the company at a sweet $500 million.
Figuring out revenue streams is now something that Facebook COO Sheryl Sandberg and her teamwill have to worry about.

8. Instagram Embodied a Cultural Shift Toward Photo Inboxes

As the future of photo-only inboxes approaches, and more people use photo-sharing apps to connect with their friends, the need for more visual communication will only intensify. The idea that social interactions will increasingly become visual and mobile is attracting widespread interest.
"Increasingly, we see people using photos to share an experience with a friend, whether it's to tell them what they had for lunch, show them a cool spot in their city that they found or to share special moments like birthdays or weddings," says Pixable's Berengeur. "The ultimate goal of sharing mobile photos is to broadcast your life to your friends instead of keeping a memory. The rise of smartphones, photo apps and social networks have made taking and sharing a photo easier than ever."

What Other Startups Can & Can't Learn From Instagram

What worked for Instagram isn't guaranteed to work for every startup. It's always easier to look back and uncover the right and wrong strategic moves. Only in retrospect is it clear that Instragram did everything right. Along the way, there were plenty of critics carping at just about every decision the company made.
There is, however, one thing that other startups can certainly learn from Instagram: Timing is everything. If Instagram had come along six months later, things might have turned out very differently. Some other company might have already executed on its ideas and it would be the one preparing to cash some very big checks

How to recover deleted files: Tutorial


Accidentally deleting files - it's something we've all done, but erasing a file isn't the only thing that can go wrong when you're working in a hurry.
It's also very easy to edit a document, save it and then later change your mind about the editing you've done.
The good news is the Previous Versions feature of Windows 7 can help you eliminate these problems by saving snapshots of your hard drive automatically, so you have the option of reverting individual files to an earlier version if necessary - or even restoring files that have been accidentally deleted.
Protect your work
Use Previous Versions to rescue files after accidental edits or deletion 
1. Enable System Protection
step 1
Click the 'Start' orb and then the 'Control Panel' shortcut to the right. Now click the 'System' icon followed by the 'System Protection' link to the left of the window.
In the Protection Settings section towards the centre of the dialog that appears, click the entry for your C: drive and then the 'Configure' button.
2. Configure restoration options
step 2
Select the option labelled 'Restore system settings and previous versions of files'. Use the slider that appears in the bottom portion of the dialog box to choose how much disk space should be set aside for previous versions of files and system backups. Click the 'OK' button once you've finished.
3. Create restore point
step 3
Windows will automatically start to create restore points and save multiple versions of files for you. Get things started by clicking the 'Create' button on the System Properties tab. Enter a name for your first restore point before clicking 'Create' - note that the date and time will be added for you automatically.
4. Complete system restore
step 4
You may have to wait for a little while as the system restore point is created, depending on the amount of data stored on your hard drive. Once it's complete, click the 'Close' button that appears to complete the backup process. You can then close the System Properties window and the Control Panel.
5. Accessing previous versions
step 5
If you discover that you've made and saved unwanted changes to a document, right-click it and select the 'Restore previous versions' option. Alternatively, you can right-click a file and select the 'Properties' option from the context menu before moving to the Previous Versions tab.
6. Check file contents
step 6
A list of previous versions of the selected file will be displayed, and you can then choose which one you would like to work with - click the 'Open' button to check the contents of a particular document. Work through the list until you identify the version that you would like to restore.
7. Restore previous version
step 7
Once you've decided which file you're interested in, click the 'Restore' button. Take note of the warning message that appears explaining that continuing will overwrite any existing file, and then only click the 'Restore' button if you're happy to continue. Once the process is complete, click 'OK'.
8. Create a copy
step 8
To avoid overwriting an existing file with one you're restoring - which could cause a problem if you accidentally restore the wrong file - it's a good idea to create a copy of the older version. To do this, click the 'Copy' button, navigate to the folder you would like to use and then click 'Copy' again.
9. Restore deleted files
step 9
If you've deleted a file by accident, right-click the folder it was stored in and select the 'Restore previous version' option from the menu that appears. You can then double-click one of the previous versions of the folder and create a copy of the file you're trying to retrieve.
10. Work with your documents
step 10
Having breathed a sigh of relief, you can now continue to work with your files as if nothing untoward ever happened. Whether you made an unwanted change to your CV or accidentally deleted some photos, Windows Previous Versions can help to save you a great deal of work and frustration.