단추를 클릭 할 때 날짜와 시간을 나열하고 목록을 UITableView 내에 배치해야하는 응용 프로그램을 만듭니다. 내 생각은 사용자가 버튼을 누를 때마다 날짜와 타임 스탬프를 가져온 다음 버튼을 클릭 할 때마다 날짜와 시간의 사전 객체 배열에 저장하는 것입니다. 또한 단추 클릭 기록에 대한 목록과 함께 UITableView를 표시하는 모달보기를로드하는 다른 단추도 있습니다.단추 누르기 기록을 사용하여 UITableView를 만드는 방법
배열 내부에 사전 항목이 채워지는 식으로 테이블을 부분적으로 처리 할 수있었습니다. 문제는 항상 모든 항목에 대해 동일한 시간과 날짜로 끝납니다.
다음은 초기에 항목이 하나있는 표의 스크린 샷입니다.
그리고이 버튼을 여러 번 두드리면 어떻게됩니까? 모든 행의 갱신 된 시간을 표시합니다.
기록을 테이블에 표시하고 업데이트하지 못하게하려면 어떻게해야합니까? NSUserDefaults를 단순히 데이터 저장에도 사용하고 있습니다.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [tableArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *customCell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
if (customCell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell"
owner:self
options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[CustomCell class]])
customCell = (CustomCell *)oneObject;
}
customCell.dateLbl.text = [tableDict objectForKey:@"Date"];
customCell.timeLbl.text = [tableDict objectForKey:@"Time"];
return customCell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 74;
}
대신이 코드를 사용했고 작동했습니다. NSDictionary * dict = [tableArray objectAtIndex : [indexPath row]]; customCell.dateLbl.text = [dict objectForKey : @ "날짜"]; customCell.timeLbl.text = [dict objectForKey : @ "시간"]; 감사! – jaytrixz