2012-02-25 3 views
0

나는 루프 등을 시도했지만 아무것도 작동하지 않는 것 같습니다. 텍스트 필드가 있고 저장을 클릭하면 테이블 셀에 텍스트를 넣습니다. 다시하면 이전 항목이 대체됩니다. 기본적으로 배열에 수동으로 addObject를 사용하지 않으면 다른 셀을 추가 할 수 없습니다. 데이터는 NSLog를 사용하여 적절하게 가져오고 데이터도 저장됩니다.Objective-C, iOS, NSKeyedUnarchiver, 하나의 셀에서 데이터 만 가져 오기

나는 문제가 여기 어딘가에 생각 :

NSMutableArray *contactArray; 

    contactArray = [[NSMutableArray alloc] init]; 
    [contactArray addObject:titlefield.text]; 
    [contactArray addObject:detailstextfield.text]; 
    [contactArray addObject:date ]; 
    [NSKeyedArchiver archiveRootObject: 
    contactArray toFile:datafilePath]; 
:

여기
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 
{ 

UITableViewCell *cell = nil; 

cell = [tableView dequeueReusableCellWithIdentifier:@"homeworkcell"]; 


if(cell == nil) 
{ 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"homework"]; 

} 



NSString *cellValue = [tabledata objectAtIndex:indexPath.row]; 

NSString *subtitle = [tablesubtitles objectAtIndex:indexPath.row]; 




cell.textLabel.text= cellValue; 

cell.detailTextLabel.text= subtitle; 

cell.textLabel.font = [UIFont systemFontOfSize:14.0]; 
cell.textLabel.backgroundColor = [ UIColor clearColor]; 
cell.detailTextLabel.backgroundColor = [UIColor clearColor];  




// Configure the cell. 

//-----------------------------------------START----------------------------Set image of cell---- 
    cellImage = [UIImage imageNamed:@"checkboxblank.png"]; 

    cell.imageView.image = cellImage; 

    //--------------------------------------------END---------------------------end set image of cell-- 

return cell; 


} 

내가 데이터를 저장하고있어 어디 : 여기

NSFileManager *filemgr; 
NSString *docsDir; 
NSArray *dirPaths; 

filemgr = [NSFileManager defaultManager]; 

// Get the documents directory 
dirPaths = NSSearchPathForDirectoriesInDomains(
               NSDocumentDirectory, NSUserDomainMask, YES); 

docsDir = [dirPaths objectAtIndex:0]; 

// Build the path to the data file 
datafilePath = [[NSString alloc] initWithString: [docsDir 
                stringByAppendingPathComponent: @"data.archive"]]; 
tablesubtitles = [[NSMutableArray alloc]init]; 

tabledata = [[NSMutableArray alloc] init]; 

// Check if the file already exists 
if ([filemgr fileExistsAtPath: datafilePath]) 
{ 
    NSMutableArray *dataArray; 

    dataArray = [NSKeyedUnarchiver 
       unarchiveObjectWithFile: datafilePath]; 


    titlestring = [dataArray objectAtIndex:0 ]; 
    detailsstring = [dataArray objectAtIndex:1]; 



    [tabledata addObject:titlestring]; 
    [tablesubtitles addObject:detailsstring]; 
    } 

실제 테이블의 다른 방법

답변

0

매번 테이블 데이터 모델을 다시 만드시겠습니까?

tablesubtitles = [[NSMutableArray alloc]init]; 

tabledata = [[NSMutableArray alloc] init]; 

이 경우 클래스 변수를 만들어야합니다.

+0

어떤 의미입니까? –

+0

전체 코드를 제공하고 셀 생성을위한 코드 – NeverBe

관련 문제