Search Results

Search found 3 results on 1 pages for 'shakeelw'.

Page 1/1 | 1 

  • How to get a reference to a method's caller object from within the method in Objective-C

    - by shakeelw
    Hi guys. I have a few text fields and text views on my application's view. The keyboard comes up when I click in anyone of them. I have a method that gets called when any one of these objects is tapped in. However, I would like the method to execute its code only if the a certain Text Field(s) or a certain Text View(s) is tapped in. I would therefore like to have something like this in the method body: { if(currentField != mySpecialField) {return;} //Rest of the method code... } Now, my question is, how do I get a reference to the currently tapped in field so that I can perform the if-check. Thanks guys. I'm a total noobee in Objective-C. :(

    Read the article

  • How to replace an object in an NSMutableArray at a given index with a new object

    - by shakeelw
    Hi guys. I have an NSMutableArray object(retained, synthesized as all) that is initiated just fine and I can easily add objects to it using the 'addObject:' method. But if I want to replace an object at a certain index with a new one in that NSMutableArray, it doesn't work. For example: ClassA.h @interface ClassA : NSObject { NSMutableArray *list; } @property (nonatomic, copy, readwrite) NSMutableArray *list; end ClassA.m import "ClassA.h" @implementation ClassA @synthesize list; (id)init { [super init]; NSMutableArray *localList = [[NSMutableArray alloc] init]; self.list = localList; [localList release]; //Add initial data [list addObject:@"Hello "]; [list addObject:@"World"]; } // Custom set accessor to ensure the new list is mutable (void)setList:(NSMutableArray *)newList { if (list != newList) { [list release]; list = [newList mutableCopy]; } } -(void)updateTitle:(NSString *)newTitle:(NSString *)theIndex { int i = [theIndex intValue]-1; [self.list replaceObjectAtIndex:i withObject:newTitle]; NSLog((NSString *)[self.list objectAtIndex:i]); // gives the correct output } However, the change remains true only inside the method. from any other method, the NSLog((NSString *)[self.list objectAtIndex:i]); gives the same old value. How can I actually get the old object replaced with the new one at a specific index so that the change can be noticed from within any other method as well. I even modified the method like this, but the result is the same: -(void)updateTitle:(NSString *)newTitle:(NSString *)theIndex { int i = [theIndex intValue]-1; NSMutableArray *localList = [[NSMutableArray alloc] init]; localList = [localList mutableCopy]; for(int j = 0; j < [list count]; j++) { if(j == i) { [localList addObject:newTitle]; NSLog(@"j == 1"); NSLog([NSString stringWithFormat:@"%d", j]); } else { [localList addObject:(NSString *)[self.list objectAtIndex:j]]; } } [self.list release]; //self.list = [localList mutableCopy]; [self setList:localList]; [localList release]; } Please help out guys :)

    Read the article

1