Adding Navigation Bar programmatically iOS

-(void)ViewDidLoad { UINavigationBar* navbar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)]; UINavigationItem* navItem = [[UINavigationItem alloc] initWithTitle:@”karthik”]; // [navbar setBarTintColor:[UIColor lightGrayColor]]; UIBarButtonItem* cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(onTapCancel:)]; navItem.leftBarButtonItem = cancelBtn; UIBarButtonItem* doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(onTapDone:)]; navItem.rightBarButtonItem = doneBtn; [navbar setItems:@[navItem]]; [self.view addSubview:navbar]; } -(void)onTapDone:(UIBarButtonItem*)item{ } -(void)onTapCancel:(UIBarButtonItem*)item{ } Swift3 let navigationBar … Read more

how to know when text is pasted into UITextView

Here is what i use to detect paste events in UITextView: // Set this class to be the delegate of the UITextView. Now when a user will paste a text in that textview, this delegate will be called. -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { // Here we check if the replacement text is equal to … Read more

Identify new iPhone model on xcode (5, 5c, 5s) [duplicate]

Objective-C & SWIFT This is working on all version like iOS 6, iOS 7 and iOS 8 etc… And updated for iPhone 6 & iPhone 6 Plus -(void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. size_t size; sysctlbyname(“hw.machine”, NULL, &size, NULL, 0); char *machine = malloc(size); sysctlbyname(“hw.machine”, … Read more

Adding unknown number of rows to ‘Static Cells’ UITableView

To add dynamic cells to a static cells table you have to override every UITableView delegate method that has an indexPath. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath -(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath -(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath . -(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath … Read more