Objective C: Change title of back button in navigation bar

You need change title of the back button from view controller which call to next view controller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.detailsViewController == nil) {
        self.detailsViewController = [[DetailsViewController alloc] initWithNibName:@"DetailsViewController" bundle:nil];
 [self.navigationController pushViewController:detailsViewController animated:YES];
 [tableView deselectRowAtIndexPath:indexPath animated:YES];

- (void)viewDidLoad {
 self.title = NSLocalizedString(@"root_tab_title_0", @"My Title");

 //Set title for back button to this controller
 self.navigationItem.backBarButtonItem =
  [[[UIBarButtonItem alloc] initWithTitle:@"My back button"
      action:nil] autorelease];

Objective C: Change title font in navigation bar

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
label.textAlignment = UITextAlignmentCenter;
label.adjustsFontSizeToFitWidth = YES;
label.minimumFontSize = 10.0;
[label setFont:[UIFont boldSystemFontOfSize:16.0]];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setText:@"My Favorite Title"];

[self.navigationItem setTitleView:label];
[label release];

Xcode: include ObjectiveC categories int static library

If you need to include ObjectiveC categories or other framework using ObjectiveC categories ( for example JSON framework ) into your own static library you probably get

-[__NSCFDictionary JSONRepresentation]: unrecognized selector sent to instance

In your project that using your static library you need to set in Project Settings for "Other Linker Flags" property two additional flags:


Objective C: Merge two images

+ (UIImage*)mergeImage:(UIImage*)first withImage:(UIImage*)second
 // get size of the first image
 CGImageRef firstImageRef = first.CGImage;
 CGFloat firstWidth = CGImageGetWidth(firstImageRef);
 CGFloat firstHeight = CGImageGetHeight(firstImageRef);
 // get size of the second image
 CGImageRef secondImageRef = second.CGImage;
 CGFloat secondWidth = CGImageGetWidth(secondImageRef);
 CGFloat secondHeight = CGImageGetHeight(secondImageRef);
 // build merged size
 CGSize mergedSize = CGSizeMake(MAX(firstWidth, secondWidth), MAX(firstHeight, secondHeight));
 // capture image context ref
 //Draw images onto the context
 [first drawInRect:CGRectMake(0, 0, firstWidth, firstHeight)];
 [second drawInRect:CGRectMake(0, 0, secondWidth, secondHeight)]; 
 // assign context to new UIImage
 UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
 // end context

 return newImage;

If you want to resize new image to new desired size use function from previous post.

Objective C: Resize image

+ (UIImage*)resizeImageWithImage:(UIImage*)image toSize:(CGSize)newSize
    // Create a graphics image context
    // draw in new context, with the new size
    [image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
    // Get the new image from the context
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    // End the context
    return newImage;

Android Emulator: invalid command-line parameter exception.

The default installation location is: C:\Program Files\Android\android-sdk.
If you set C:\Program Files\Android\android-sdk as SDK Location (Window -> Preferences -> Android) and try to run android application from Eclipse most likely you'll get an error:

[Emulator] invalid command-line parameter: Files\Android\android-sdk\tools/emulator-arm.exe.
[Emulator] Hint: use '@foo' to launch a virtual device named 'foo'.
[Emulator] please use -help for more information

In my opinion, this is because of space in Program Files,
so set SDK Location for 32-bit Windows


and for 64-bit Windows


WP7: Sending "POST" data and receive response

Let's send "POST" data from our Windows Phone and get response.
  1. Create Windows Phone Application named "SendPOSTdata".
  2. In MainPage.xaml.cs include some "using":
    using System;
    using System.IO;
    using System.Text;
    using System.Diagnostics;
    using System.Net;
    using System.Windows;
    using Microsoft.Phone.Controls;
  3. Create loaded event handler:
    using System;
    public MainPage()
        Loaded += new RoutedEventHandler(MainPage_Loaded);
    void MainPage_Loaded(object sender, RoutedEventArgs e)
        System.Uri myUri = new System.Uri("http://myPageUrlAddress.com/");
        HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(myUri);
        myRequest.Method = "POST";
        myRequest.ContentType = "application/x-www-form-urlencoded";
        myRequest.BeginGetRequestStream(new AsyncCallback(GetRequestStreamCallback),myRequest);
  4. Now we need create our "POST" data stream:
    void GetRequestStreamCallback(IAsyncResult callbackResult)
        HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
        // End the stream request operation
        Stream postStream = myRequest.EndGetRequestStream(callbackResult);
        // Create the post data
        string postData = "param1=value1&param2=value2";
        byte[] byteArray = Encoding.UTF8.GetBytes(postData);
        // Add the post data to the web request
        postStream.Write(byteArray, 0, byteArray.Length);
        // Start the web request
        myRequest.BeginGetResponse(new AsyncCallback(GetResponsetStreamCallback), myRequest);
  5. And at the end receive response:
    void GetResponsetStreamCallback(IAsyncResult callbackResult)
        HttpWebRequest request = (HttpWebRequest)callbackResult.AsyncState;
        HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(callbackResult);
        using (StreamReader httpWebStreamReader = new StreamReader(response.GetResponseStream()))
            string result = httpWebStreamReader.ReadToEnd();
            //For debug: show results
  6. Run.