在我看來,我想要一個右上角的添加按鈕,當我們點擊它時,它會給出帶有文本字段的警報視圖。當我們添加數據並在alertview上單擊添加按鈕時,應該使用用戶輸入的文本創建一個新單元格。在點擊添加按鈕時在uitableview底部添加一個新單元格
我的代碼:
-(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;
}
請幫我在底部添加新小區表。
由於以下原因,我的應用程序崩潰:***由於未捕獲的異常'NSInternalInconsistencyException',原因:'無效的更新:無效的行數在第0節中的行終止應用程序。 update(8)必須等於更新前(8)的該部分中包含的行數,加上或減去從該部分插入或刪除的行數(插入1個,刪除0個)。 – anjum 2012-04-14 09:40:15
什麼是您的UITableViewDataSource,並且當您向該表中添加一行時,是否向其中添加了一個元素? – 2012-04-14 11:46:15