当我添加新行时,它会添加一个新行,并将当前日期作为标题。以下是我的代码。我将“NSDate日期”更改为什么,以便用户可以输入他们想要的任何标题?
(void)insertNewObject:(id)sender
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
[_objects insertObject:[NSDate date] atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
答案 0 :(得分:0)
您可以将新UIAlertView
与纯文本条目一起使用。您还必须更改表格查看单元格以显示NSString
而不是NSDate
。 (哦,你必须在课堂上采用UIAlertViewDelegate
。
-(void)insertNewObject:(id)sender
{
UIAlertView * getTitle = [[UIAlertView alloc] initWithTitle:@"title" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; // should give proper cancel/accept buttons
getName.alertViewStyle = UIAlertViewStylePlainTextInput;
[getTitle show];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
NSString * userEnteredThisString = [[alertView textFieldAtIndex:0] text];
[_objects insertObject:userEnteredThisString atIndex:0];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}