在我看来,我希望在右上角有一个添加按钮,当我们单击它时,它会提供带有文本字段的警报视图。当我们添加数据并单击 alertview 上的添加按钮时,应使用用户输入的文本创建一个新单元格。
我的代码:
-(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;
}
请帮助我在底部的表格中添加新单元格。