1 개의 버튼으로 구성되는 기본 뷰 컨트롤러가 있는데,이 버튼을 탭하면 상세 뷰 컨트롤러와 테이블이있는 모달 뷰 컨트롤러를 단순히 시작하는 다른 버튼을 푸시합니다. 이 상세보기 컨트롤러에는 모달 뷰 컨트롤러의 테이블에 의해로드 된 배열에 새 객체를 추가해야하는 탭이 있습니다.NSMutableArray가 객체를 추가하지 않음
문제는 새 객체 버튼을 추가해도 NSMutableArray에 추가되지 않는다는 것입니다.
기본보기에 단추를 놓고 NSMutableArray에 개체를 추가하는 것과 같은 방법으로 지정하면 작동합니다. 네비게이션 컨트롤러와 모달 뷰를 통해 제시된 다른 뷰 컨트롤러에 버튼을 배치하면 작동하지 않습니다.
- (IBAction)confirmBtnPressed
{
// Gets the current time and formats it
NSDate *timeNow = [NSDate date];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
[timeFormatter setDateFormat:@"hh:mm a"];
// Gets the current date and formats it
NSDate *dateNow = [[NSDate alloc] init];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMM dd, yyyy"];
NSString *currentTime = [timeFormatter stringFromDate:timeNow];
NSString *currentDate = [dateFormatter stringFromDate:dateNow];
NSString *timestamp = currentTime;
NSString *date = currentDate;
// This is where values gets saved
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:timestamp forKey:kTimeStampText];
[defaults setObject:date forKey:kDateText];
[defaults synchronize];
NSString *timeToday = [defaults objectForKey:kTimeStampText];
NSString *dateToday = [defaults objectForKey:kDateText];
tableVC.tableDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:timeToday, @"Time", dateToday, @"Date", nil];
[tableVC.tableArray addObject:tableVC.tableDict];
[tableVC.table reloadData];
}
버튼이 테이블 모달를 누르면로드 할 때 다음 주 뷰 컨트롤러에 내 코드입니다 :
여기에 버튼 디테일 뷰 컨트롤러를 누르면 내 코드의
// Table loaded
- (IBAction)viewHistoryPressed:(id)sender
{
if (!self.historyViewController)
{
self.historyViewController = [[HistoryViewController alloc] initWithNibName:@"HistoryViewController" bundle:nil];
}
[self presentModalViewController:historyViewController animated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *time = [defaults objectForKey:kTimeStampText];
NSString *date = [defaults objectForKey:kDateText];
tableDict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:time, @"Time", date, @"Date", nil];
tableArray = [[NSMutableArray alloc] initWithObjects:tableDict, nil];
}
스크린 샷 :
여기 내 viewDidLoad에 내 테이블 뷰 컨트롤러의
상세보기 :
테이블보기 : 기본보기의
** ** kDateText ** 및 ** kTimeStampText **는 어디에서 정의 되었습니까? 또한 ** 시간 ** 및 ** 날짜 **가 비어 있지 않은지 확인하십시오. – WrightsCS
@CReaTuS 나는 그들을 받아 들였다. 나는 다만 작동하지 않는 응답을 받아들이지 않는다. – jaytrixz
@WrightsCS 예, 그것은 "타임 스탬프"와 @ "날짜"로 정의됩니다. – jaytrixz