In my view I want an add button on top right corner, when we click on it it gives alert view with text field. When we add data and click add button on alertview a new cell should be created with text which user has entered.
My code:
-(IBAction)addNewBreed:(id)sender{
UIAlertView *addAlert=[[UIAlertView alloc]initWithTitle:@"Add New Breed" message:@"\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add",nil];
UITextField *addTextField=[[UITextField alloc]initWithFrame:CGRectMake(12,45,260,25)];
[addTextField becomeFirstResponder];
[addTextField setBackgroundColor:[UIColor whiteColor]];
addTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
[addAlert addSubview:addTextField];
[addAlert show];
[addAlert release];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
if ([buttonTitle isEqualToString:@"Add"]) {
[treeTable insertRowsAtIndexPaths:[NSArray arrayWithObject:addIndexPath] withRowAnimation:UITableViewRowAnimationBottom];
}
else
return;
}
Please help me with adding new cell to table at the bottom.
add the new value in array or dictionary (whatever you r using to display the cell.textlable.text) and just use the reload data method of UitableView.
[MyTableView ReloadData];