Thursday, July 7, 2011

Short Codes useful for mac apps



Hi!

This blog will contain some very basic concepts that we mostly use in iphone apps but not sure how to implement in MacApps.Hope it will save your time in researching.


1. Loading a url in a webView for Mac App


[ [web mainFrame ] loadRequest: [ NSURLRequest requestWithURL: [NSURL URLWithString:@"http://www.google.com/" ] ];

Here ,"web" is an object of WebView.

2. Get the tableView row number that was selected (using single tap)


For this you need to set the tableView delegate & use the below method
- (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(NSInteger)row{
rowSelected = row;
return YES;
}

3. Showing an alert Message


NSString *theAlertMessage = [NSString stringWithFormat: @"Already added to rhymes sticky."];
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setAlertStyle:NSCriticalAlertStyle];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:theAlertMessage];