2012-06-22 4 views
0

새 행을 추가하면 현재 현재 날짜가 제목 인 새 행이 추가됩니다. 아래 코드는 제가 가지고있는 코드입니다. 사용자가 원하는 제목을 입력 할 수 있도록 "NSDate date"를 어떻게 변경합니까?날짜를 쓰기 가능한 제목으로 바꾸려면 어떻게합니까?

(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

것 같습니다. 내가 jQuery과 자습서를 검색하거나 아마 iOS에서 책을 읽고 추천 할 것입니다 아마도 누군가가 추천 할 수 있습니다. –

답변

0

일반 텍스트 입력으로 새로운 UIAlertView을 사용할 수 있습니다. NSDate 대신 NSString을 표시하도록 표보기 셀을 변경해야합니다. (아, 그리고 당신은 클래스의 UIAlertViewDelegate을 채택해야합니다. 당신은 엑스 코드의 기본 MasterViewController 프로젝트를 생성 한 것 같은

-(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]; 

} 
관련 문제