How To Add A Nice Background Image To Your Grouped Table View

without comments

http://howtomakeiphoneapps.com/2009/03/how-to-add-a-nice-background-image-to-your-grouped-table-view/

What you need to do is create a view with your background image and add that view to your app’s window. Then you must set the table view’s background color to “clearColor”.

Here is how you would do that from the app delegate:

UIView *backgroundView = [[UIView alloc] initWithFrame: window.frame];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"TableViewBackground.png"]];
[window addSubview:backgroundView];
[backgroundView release];

yourTableViewController = [[ATableViewController alloc] initWithStyle:UITableViewStyleGrouped];
yourTableViewController.view.backgroundColor = [UIColor clearColor];
[window addSubview:yourTableViewController.view];

[window makeKeyAndVisible];

yourTableViewController is declared at the top level of the app delegate and ATableViewController is a subclass of UITableViewController that simply displays the rows and sections in the example.

Written by grantmcinnes

November 3rd, 2009 at 11:17 am

Posted in iPhone

Lessons for the Beginning iPhone Developer

without comments

Written by grantmcinnes

October 26th, 2009 at 2:47 pm

Posted in iPhone

Adding a Contact to the iPhone Address Book

without comments

http://www.modelmetrics.com/tomgersic/iphone-programming-adding-a-contact-to-the-iphone-address-book/

We then create our reference to the iPhone Address Book with a call to ABAddressBookCreate():

        ABAddressBookRef iPhoneAddressBook = ABAddressBookCreate();

And then we create a new person record:

        ABRecordRef newPerson = ABPersonCreate();
 

At this point, we haven’t saved anything to the address book yet, but we can start adding data to the person record. To do this, we use ABRecordSetValue, but some fields need to be formatted differently from others. For some, like first name and last name, we can just pass in a string:

        ABRecordSetValue(newPerson, kABPersonFirstNameProperty, @”John”, &error);
        ABRecordSetValue(newPerson, kABPersonLastNameProperty, @”Doe”, &error);

kABPersonFirstNameProperty and kABPersonLastNameProperty are constants defined by Apple that specify which fields you’re saving. They’re listed in the XCode documentation under Personal Information Properties in the ABPerson Reference document. We can also set some other fields in this manner, such as company and title:

        ABRecordSetValue(newPerson, kABPersonOrganizationProperty, @”Model Metrics”, &error);
        ABRecordSetValue(newPerson, kABPersonJobTitleProperty, @”Senior Slacker”, &error);

Where it gets a bit trickier is when we want to set our phone, email, or address properties, because these fields use ABMutableMultiValueRef rather than strings to store the data, and the specific data types of the values vary a bit depending on which one we’re talking about. For phone, we would do something like this:

 
        ABMutableMultiValueRef multiPhone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
        ABMultiValueAddValueAndLabel(multiPhone, @”1-555-555-5555″, kABPersonPhoneMainLabel, NULL);
        ABMultiValueAddValueAndLabel(multiPhone, @”1-123-456-7890″, kABPersonPhoneMobileLabel, NULL);            
        ABMultiValueAddValueAndLabel(multiPhone, @”1-987-654-3210″, kABOtherLabel, NULL);        
        ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiPhone,nil);
        CFRelease(multiPhone);
       

 The first two phone types (kABPersonPhoneMainLabel and kABPersonPhoneMobileLabel) are listed as Phone Number Properties in the ABPerson Reference, along with kABPersonPhoneHomeFAXLabel, kABPersonPhoneWorkFAXLabel, and kABPersonPhonePagerLabel. Despite the fact that the two fax numbers and the pager number seem fairly useless (you can’t send a fax from your phone, and who has a pager anymore?) but there’s nothing listed there for Other, or Work Phone or anything like that. That’s where the Generic Property labels come into play:

      kABWorkLabel;
      kABHomeLabel;
      kABOtherLabel;

Those will file the phone numbers as Work, Home, and Other, respectively. After adding the values to the ABMutableMultiValueRef, we need to call ABRecordSetValue, only this time instead of passing a string in for the third parameter, we pass in multiPhone. Then be sure to free up the memory with CFRelease.

Adding email addresses to the record is pretty similar to adding phone numbers, where we create an ABMutableMultiValueRef of strings:

        ABMutableMultiValueRef multiEmail = ABMultiValueCreateMutable(kABMultiStringPropertyType);
        ABMultiValueAddValueAndLabel(multiEmail, @”johndoe@modelmetrics.com”, kABWorkLabel, NULL);
        ABRecordSetValue(newPerson, kABPersonEmailProperty, multiEmail, &error);
        CFRelease(multiEmail);

Where it gets a little different is when we go to set the street address values. While we do still use an ABMutableMultiValueRef, we won’t be using kABMultiStringPropertyType. To set the street address, we use kABMultiDictionaryPropertyType instead, so we have to create an NSMutableDictionary, and the method calls end up being a bit different:

            ABMutableMultiValueRef multiAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
           
            NSMutableDictionary *addressDictionary = [[NSMutableDictionary alloc] init];

            [addressDictionary setObject:@"750 North Orleans Street, Ste 601" forKey:(NSString *) kABPersonAddressStreetKey];
            [addressDictionary setObject:@"Chicago" forKey:(NSString *)kABPersonAddressCityKey];
            [addressDictionary setObject:@"IL" forKey:(NSString *)kABPersonAddressStateKey];
            [addressDictionary setObject:@"60654" forKey:(NSString *)kABPersonAddressZIPKey];

            ABMultiValueAddValueAndLabel(multiAddress, addressDictionary, kABWorkLabel, NULL);
            ABRecordSetValue(newPerson, kABPersonAddressProperty, multiAddress,&error);
            CFRelease(multiAddress);

kABWorkLabel means that we’re setting this as the contact’s work address. And to add it to the contact record, we call ABRecordSetValue as before, releasing the memory afterward.

 The last step is to add the new record to the address book, and save it back to the device:

        ABAddressBookAddRecord(iPhoneAddressBook, newPerson, &error);
        ABAddressBookSave(iPhoneAddressBook, &error);

And then we can check for any errors:

        if (error != NULL)
        {

                  NSLog(@”Danger Will Robinson! Danger!”);

        }

Written by grantmcinnes

October 26th, 2009 at 2:37 pm

Posted in Uncategorized

Adhoc Distribution Process

without comments

Written by grantmcinnes

October 26th, 2009 at 12:34 pm

Posted in iPhone

ABAddressBookRef example

without comments

- (void)AddressBookInMotion
{
   
    ABAddressBookRef m_addressbook = ABAddressBookCreate();
   
    if (!m_addressbook) {
        NSLog(@”opening address book”);
    }
   
//    CFArrayRef people = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
   
   
    ABRecordRef person = ABPersonCreate();
   
    //ABRecordSetValue(person, kABPersonPrefixProperty, @”Mr.” , nil);
    ABRecordSetValue(person, kABPersonFirstNameProperty, @”Jane” , nil);
    //ABRecordSetValue(person, kABPersonMiddleNameProperty, @”M.” , nil);
    ABRecordSetValue(person, kABPersonLastNameProperty, @”Doe”, nil);
    //ABRecordSetValue(person, kABPersonSuffixProperty, @”MD” , nil);
    //ABRecordSetValue(person, kABPersonNoteProperty, @”My Company, we help everyone”, nil);
    //ABRecordSetValue(person, kABPersonEmailProperty, @”jane.doe@money.com”, nil);
   
   
    ABAddressBookAddRecord(m_addressbook, person, nil);
    ABAddressBookSave(m_addressbook, nil);

   

    CFRelease(person);
    CFRelease(m_addressbook);
   
   
}

Written by grantmcinnes

September 1st, 2009 at 2:34 pm

Posted in iPhone

Survey Results: Which Smartphone Will Own the Healthcare Market?

without comments

Written by grantmcinnes

August 21st, 2009 at 3:59 pm

Posted in Uncategorized

Foo

without comments

foo bar

Written by grantmcinnes

August 7th, 2009 at 9:55 am

Posted in Uncategorized

log4net example

without comments

 

In a recent project, I needed to implement logging and decided to use the log4net.dll which I have seen referenced in a number of different open source projects. Here are the steps I had to taken in order to use log4net in my project:

 

1. Download the log4net.dll from http://sourceforge.net/projects/log4net/

2. Add a reference to your project that includes the downloaded log4net.dll

3. Add a log4net section to your web.config/app.config file:

<configuration>
    <configSections>
            <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
        </sectionGroup>
    </configSections>
</configuration>

4. Add a log4net.config file to your project with the following configuration:

<?xml version="1.0" encoding="utf-8"?>
<log4net debug="true">
  <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
    <param name="File" value="log4netoutput.log" />
    <param name="AppendToFile" value="true" />
    <layout type="log4net.Layout.PatternLayout">
      <param name="ConversionPattern" value="%d [%t] %-5p [%c] %m%n" />
    </layout>
  </appender>
  <root>
    <level value="DEBUG" />
    <appender-ref ref="LogFileAppender" />
  </root>
</log4net>

There are various Appenders you can create but this example uses a text file to log the results into the bin directory of the application. There are also different values that can be used as part of the ConversionPattern to get different output.

5. Be sure to change the properties of the log4net.config file in your project for the Copy to Output Directory attribute to Copy Always. I spent hours debugging my code because the config file was not being copied into the bin directory and log4net did not throw any exceptions. Since I had not used log4net before, I was making the assumption the problem was with my code and/or config file settings.

6. Here’s my code from a test method to make sure log4net is working correctly:

[Test]
public void TestLog4NetOnItsOwn()
{
    ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    XmlConfigurator.Configure(new FileInfo(Settings.Default.log4net_config_file)); 
    logger.Debug("Here is a debug log.");
}

To log results to the console, include the following line of code:

BasicConfigurator.Configure();

 

I’ve seen other posts that reference the log4net.config file in the Assembly.cs file rather than in code:

[assembly: log4net.Config.XmlConfigurator(ConfigFile="log4net.config", Watch = true)]

 

Other Posts and Resources:

http://it.toolbox.com/blogs/daniel-at-work/using-log4net-in-cnet-26794

http://geekswithblogs.net/bsherwin/archive/2008/02/15/119657.aspx

Written by grantmcinnes

June 25th, 2009 at 2:45 pm

Posted in .NET Programming

How to Open an MVC project in Visual Studio 2010

without comments

Written by grantmcinnes

June 9th, 2009 at 11:25 am

Posted in .NET Programming

Example IsapiRewrite4.ini File for IsapiRewrite4

without comments

 

– Redirect attacks

RewriteCond %{REMOTE_ADDR} 10.10.1.0
RewriteRule ^/(.*)$ /$1 [F]

– Redirect from http://foo.com to http://www.foo.com

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

Written by grantmcinnes

May 28th, 2009 at 3:20 pm

Posted in Technology