Popular Posts

May 17, 2011

Select a particular row from table view.

I have faced a problem to selecting a row of a table view. After a long time I have found  the solution. Here is the code that can  help you to select a particuler row from a table view.It  works like radio button....

 - (void)tableView:(UITableView *)table didSelectRowAtIndexPath:(NSIndexPath *)newIndexPath {

    // When a new selection is made, display a check mark on the newly-selected time signature and remove check mark from old time signature.

    MetronomeAppDelegate *appDelegate = (MetronomeAppDelegate *)[[UIApplication sharedApplication] delegate];

    NSIndexPath *oldIndexPath = [NSIndexPath indexPathForRow:([appDelegate timeSignature] - 2) inSection:0];
    [[table cellForRowAtIndexPath:oldIndexPath] setAccessoryType:UITableViewCellAccessoryNone];
    [[table cellForRowAtIndexPath:newIndexPath] setAccessoryType:UITableViewCellAccessoryCheckmark];
    [table deselectRowAtIndexPath:newIndexPath animated:YES];
    if (newIndexPath.row == 0) {
        [appDelegate setTimeSignature:TimeSignatureTwoFour];
    else if (newIndexPath.row == 1) {
        [appDelegate setTimeSignature:TimeSignatureThreeFour];
    else {
        [appDelegate setTimeSignature:TimeSignatureFourFour];

No comments:

Post a Comment