Archive

Archive for the ‘iPhone’ Category

iPhone Simulator: I thought it was good!

November 12, 2009 Gaurav Sohoni Leave a comment

No doubt iPhone simulator is one of its kind and as far as User Interface is concerned, I think iPhone Simulator does justice to all the Library elements that one could play with while developing the application. But I did come across somethings which really did bother me for sometime before I got used to them.

First point was related to the PERFORMANCE. Currently the simulator uses the Mac processor for simulation. If there could have been a way that could make the iPhone simulator behave as if it was running on a 600MHz processor with only 256 MB of RAM, I think it would have been a real boon for developers. This is because though you know almost always that the performance on real iPhone is gonna be low as compared to the simulator, sometimes the difference is astonishing :) :( .

Second was with MEMORY. You could go ahead and allocate lot more memory on the simulator with your application still not worried about the load but as soon as you do that on iPhone, you would realize that your code actually needs a lot of rework.

Then other points were related to graphics. There were cases where simulator worked fine but iPhone did not and then there were others which left simulator frowning.

Not to forget the positioning of info icon, toolbars etc (which would be positioned differently on simulator and on actual iPhone).

One should always keep in mind that there is no alternative to On Device testing. Simulator does help but to a certain extent (and is always required) but an iPhone is a must.

So go get the iPhone and let your development rock.

iPhone – Set or change title of UIBarButtonItem

October 29, 2009 Gaurav Sohoni Leave a comment

Now this is very trivial and does not need a lot of work. I had googled for this but got some not so good answers so I tried out something and it works fine.

So basically what we are trying to achieve here is:

1) First create a UIBarButtonItem and put it in navigation.

2) Changing the title of the BarButtonItem on tap.

We do this by first declaring the button (in this case, the title is ‘Edit’) and attach a function to it which basically does something and also changes the Button Label to ‘Done’.

So lets first add the button on view load:


self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStyleBordered target:self action:@selector(alterMode) ];

So the action ‘alterMode’ is now attached with the rightBarButtonItem. Now we just need our altermode method to change the title of the button and we are done.


-(void) alterMode {
  if(self.navigationItem.rightBarButtonItem.title == @"Edit") {
    //Do your stuff;
    self.navigationItem.rightBarButtonItem.title = @"Done";
  }
  else{
    //Do your stuff;
    self.navigationItem.rightBarButtonItem.title = @"Edit";
  }
}

That is all you need to do. Try it out. Hope it helps someone out there.

iPhone: TextField custom textDidChange action

August 27, 2009 Gaurav Sohoni 2 comments

While working on a project, I came across a requirement where I was required to fire an action on textfield text change. I did not find any method that apple provides like it does for searchbar text change. With some research on google, I went ahead and created a custom method which was then added on textfield event change namely UICOntrolEventEditingChanged.

This was what I did to make it work.

In ViewDidLoad, I added the following code:


[myTextfield addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UICOntrolEventEditingChanged];

Here I am attaching ‘textFieldDidChange’ method which will be called once the text in the myTextfield changes. I named it like this to make it sound more like the method for searchbar textchange method.

The actual method is:

-(void)textFieldDidChange {
// whatever you wanted to do
someLabel.text = myTextfield.text;
}